Demistifying CORS

placeholder-image

Ever wondered how CORS (Cross-Origin Resource Sharing) works but found the technical jargon too complex? I struggled with it so I decided to break it down in a simple way.

🏡 Imagine the internet as a neighborhood, where every website is a unique house. Your website is ‘Example.com’, a little house in this digital district.

🍚 Now, let’s say you need to borrow some rice (or in our case, data) from your neighbour, ‘AnotherSite.com’. There’s a catch, because in our neighbourhood, there’s a rule for safety: you can only use things from your own house. This is the “Same-Origin Policy”, a standard safeguard to prevent websites from accessing each other’s data without permission.

🚦 This feels restrictive because sometimes it can be beneficial to share resources and here’s where CORS comes into play! For example through CORS “AnotherSite.com” can create a written permission to “Example.com” to borrow rice. This permission slip lets browsers know it is safe and approved to share resources with a site from a different place.

So next time you encounter CORS think It’s all about making sharing safe and friendly in our online world!