CORS (Cross-Origin Resource Sharing) is the set of HTTP headers a server uses to say which other origins may read its responses.
A web page can send requests anywhere, but it can only read the answers from its own origin unless the other server says otherwise. Once you know how CORS works, the most confusing error in front-end development becomes a quick fix.
What counts as an origin
An origin is three things together: the scheme (https), the host (shop.example.com) and the port (443 by default for HTTPS). Change any one of them and you are talking to a different origin. The path, the query string and the fragment don't count.
Compared with https://shop.example.com | Same origin? | Why |
|---|---|---|
https://shop.example.com/cart | Yes | Only the path differs |
http://shop.example.com | No | Different scheme |
https://api.example.com | No |
Wondering how this was made? How we make these