1 / 7

What Is Cross-Origin Resource Sharing in Web Development

Cross-origin resource sharing (CORS) is an important concept in web development that allows resources to be requested from another domain outside the domain from which the resource originated.

M260
Download Presentation

What Is Cross-Origin Resource Sharing in Web Development

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. What Is Cross What Is Cross- -Origin Resource Sharing in Origin Resource Sharing in Web Development Web Development Introduction Web development refers to the process of creating websites and web applications. It encompasses several disciplines like front-end development, back-end development, database management, server configuration etc. Some common types of web development include: •Static Website Development - Includes plain HTML, CSS, JavaScript sites. •Dynamic Website Development - Websites generated from server-side code like PHP, Python, Ruby etc. •Web Application Development - Complex software apps like social networks, e- commerce sites etc. •Progressive Web Apps - Mobile-first websites that work like native apps. •Single Page Applications - Apps that load single HTML page and update views without reloading. Cross-origin resource sharing (CORS) is an important concept in web development that allows resources to be requested from another domain outside the domain from which the resource originated. CORS defines a way for client web applications to access resources on a different domain than the one which served the application, enabling cross-domain data transfers. What is Cross-Origin Resource Sharing in Web Development Cross-origin resource sharing (CORS) is a mechanism that allows resources on a web page to be requested from another domain outside their own domain. It defines a way for the browser and server to interact securely via specified HTTP headers that determine whether or not to allow cross-origin requests. For example, a client-side web app served from https://domain-a.com makes a request for resources to https://domain-b.com. This is considered a cross-origin HTTP request. Without CORS, such cross-origin requests would be blocked by browsers by default as a security precaution. CORS provides a secure way to allow cross-origin requests by defining the following: •HTTP headers - Special headers like Origin, Access-Control-Allow-Origin indicate an appropriate cross-origin request. •Preflight requests - The browser makes an OPTIONS request to check if cross-origin request is allowed before making actual request.

  2. •Credentials transfer - Cookies, authentication etc can be securely sent cross-origin. So, in summary, CORS allows servers to specify who can access their resources through specified HTTP headers. And browsers use those headers to allow cross-origin requests accordingly in a secure manner. Purpose of CORS The main purposes of CORS are: •To enable secure cross-origin data transfers between browsers and servers. •To prevent cross-origin HTTP requests from other domains that servers do not permit. •To enable modern web application to access resources securely from multiple domains. •To remove restrictions on sharing resources cross-origin imposed due to the same-origin policy. The same-origin policy restricts resources like JS from accessing resources from different origins. CORS provides a secure mechanism to lift this restriction to enable valid cross-origin requests. Implementation of CORS CORS is implemented through the use of standard HTTP headers that allow servers and browsers to handle cross-origin requests securely: 1. Origin Header This header indicates the origin domain requesting the resource. It is added automatically by browsers to all cross-origin requests. Copy codeOrigin: <https://domain-a.com> 2. Access-Control-Allow-Origin This header specifies origins allowed to access resources on the server through CORS. The server sets this in response to preflight requests. Copy codeAccess-Control-Allow-Origin: <https://domain-a.com> 3. Preflight Request For complex requests browsers first send an OPTIONS request asking if cross-origin request is allowed. Server replies with access headers. 4. Credentials Headers

  3. Headers like Access-Control-Allow-Credentials indicate browsers whether cookies, authentication etc. can be sent cross-origin. Based on the permitted origins and headers set by servers, browsers determine whether cross- origin requests should be allowed or blocked. Why CORS is Important CORS is important and useful for the following reasons: •Enables cross-origin resource access - The primary benefit of CORS is it allows cross- domain resource access which is restricted by default otherwise. •Modern web apps require CORS - Modern JavaScript heavy apps served from one domain frequently need to access APIs on another domain. CORS enables this. •Secure data transfer - With CORS, credentials like cookies and login details can be securely sent cross-origin. •Flexibility - Resources can be used by multiple sites. Without CORS, cross-origin requests would always be blocked by browsers. •Performance - CORS allows assets like fonts to be stored on a CDN for better loading performance. •Responsive design - CORS enables content from different domains to be used on a responsive website or web app. So, in summary, CORS crucially enables cross-origin resource access on the modern web while still maintaining security protections of same-origin policy. Advantages and Disadvantages of CORS Some key advantages of using CORS include: •Secure cross-origin resource sharing. •Eliminates need for less secure techniques like JSONP. •Cookies and login credentials can be sent securely. •Easy to implement using standard HTTP headers. •Granular control for server on who can access resources. •Enables use of CDNs and assets across domains. Some potential disadvantages are: •Overhead of preflight request options check. •Access-Control headers can expose information about APIs. •Need to handle errors like CORS misconfiguration carefully. •Browsers may not support newer CORS features immediately. Is CORS a Cost Saving Factor?

  4. CORS can potentially lead to cost savings in certain cases: •CDN Usage - Resources like images, CSS and JS files can be stored on fast, cheaper CDNs instead of same domain. •Shared Resources - Common resources and APIs can be reused across different web apps reducing duplication. •Caching - Browsers can cache CORS resources leading to fewer requests. •Productivity - CORS makes web development in Kukatpally more flexible and productive by reducing cross-origin limitations. However, CORS requires properly configuring servers to handle preflight requests and headers which takes some effort. There is also the cost of initial implementation and testing of CORS. So overall, CORS enables cost savings through improved performance, caching, shared resources usage but requires upfront configuration investment. The benefits tend to outweigh the costs in the long run for modern web applications. Benefits of CORS Some major benefits provided by Cross-Origin Resource Sharing are: •Cross-domain requests - Enables AJAX and JavaScript/browser apps to make HTTP requests to another domain. •Access control - Server can specify origins allowed access through Access-Control headers. •Credentials transfer - Cookies, HTTPS authentication can securely be sent cross- origin. •Flexibility - Resources can be used easily across domains and origins. •Performance - Assets can be served from a high-speed CDN. Saves bandwidth. •Productivity - No need for less secure workarounds. Rapid API and resource sharing. •Responsive web - Components can be safely reused across sites enabling responsive design. Overall, CORS enables key web development capabilities like cross-domain requests, responsive design and performance which would not be possible otherwise due to same-origin policy restrictions. Who is Well Known for CORS in Web Development? Some major contributors that helped define and implement CORS for web development include: •W3C Web Applications Working Group - Developed the initial CORS specification and standards. •World Wide Web Consortium (W3C) - The main standards organization for the web that publishes CORS specs.

  5. •Browser vendors - Major browsers like Chrome, Firefox, Safari implemented support for CORS. •HTML 5 Working Group - Helped incorporate CORS into HTML 5 standard. •HTTP Working Group - Defined relevant HTTP headers like Origin for CORS implementation. •Modern web frameworks - Web development Frameworks like React, Angular, Vue.js adopted CORS to enable building complex apps. •Web developers - Adoption of CORS in apps enabled more flexible and usable web experiences. So, in summary, CORS emerged through the joint efforts of standards bodies, browser vendors, framework developers and the web dev community to meet the needs of complex modern web applications. Why Colourmoon is the Best Web Development Company in Kukatpally Colourmoon Technologies is well recognized as one of the leading web development companies based in Kukatpally, Hyderabad due to the following key strengths: •Industry experience - 10+ years’ experience building 150+ web apps for global clients. •Expertise - Specialists in latest web technologies like React, Node.js, Graph. •Methodology - Proven Agile process ensures on-time delivery of scalable and user- friendly apps. •Talent - Strong team of web architects, UI/UX designers, QA experts and digital marketers. •Support - Provides ongoing maintenance and support even after project completion. •Domain experience - Extensive experience in major industries like finance, healthcare, real estate. •Trust - 100+ satisfied clients vouch for their professionalism, transparency and timely delivery. •Awards - Recognized through global awards like AWS Advanced Consulting Partner status. •Cost effective - Competitive pricing models like fixed cost projects and dedicated developer resources. •Training - In-house training center Colourmoon Academy nurtures fresh talent. •Innovation - Heavily invests in R&D of next-gen technologies like AI, ML. So, if you are looking for an expert technology partner for web development services in Hyderabad and across India, Colourmoon Technologies is an ideal choice. Their expertise in latest web technologies combined with Agile processes enables delivery of innovative, scalable and award-winning web solutions. Final Thoughts

  6. In summary, Cross-Origin Resource Sharing (CORS) crucially enables cross-domain requests on the modern web by allowing servers to specify permitted origins through HTTP headers. CORS makes cross-origin data transfers more flexible and secure. The benefits like increased responsiveness and performance outweigh the minor disadvantages due to the extra preflight requests. Leading web technology contributors like standards bodies, browser vendors and website frameworks were critical to the adoption of CORS. For enterprises seeking an expert web development partner to build innovative solutions using such latest technologies, Colourmoon Technologies is an ideal choice. Their extensive experience, expertise in emerging technologies and proven methodology ensures delivery of award-winning web apps optimized for performance and scale. FAQs Q: What are the key CORS security features? A: The main security features of CORS are preflight requests to check permissions, use of standard HTTP headers for access control, and options for securely sending credentials like cookies cross-origin. Q: Does CORS completely replace JSONP? A: CORS is the modern standard approach recommended for cross-origin requests instead of using less secure workarounds like JSONP which have risks. However, JSONP may still be used in some legacy apps not ready to implement CORS. Q: What are examples of CORS headers? A: Some common CORS headers are Origin, Access-Control-Allow-Origin, Access-Control- Allow-Credentials and Access-Control-Allow-Methods. Q: How does CORS affect web performance? A: Implemented properly, CORS improves performance through enabling CDN usage and browser caching of assets. The preflight requests add a bit of overhead which is usually insignificant for the benefits. Q: What are the prerequisites to implement CORS? A: CORS requires browser support, server configuration to handle OPTIONS requests and respond with appropriate headers, as well as testing cross-origin requests locally. Thank you for reading my blog, If you are looking for the best website development then, connect with us and build a responsive website.

More Related