Skip to main content

Command Palette

Search for a command to run...

🚧 CORS Explained Like You're 5

Published
β€’1 min read
S

Building AI systems and writing about how they actually work. Master of AI @ University of Technology Sydney. Previously B.Tech CS with focus on IoT. I believe the best way to learn is to explain. That's why I'm documenting tech concepts with simple analogies (@sreekarreddy.com). AWS Certified β€’ Azure AI Certified β€’ Neo4j Professional β€’ Google Data Analytics When not coding: exploring Sydney, working on side projects, and teaching tech to anyone who'll listen.

A club's guest list for websites

Day 42 of 149

πŸ‘‰ Full deep-dive with code examples


The Exclusive Club

You're at a club. The bouncer has a guest list.

You: "I'm from VIP Corp!" Bouncer: checks list "VIP Corp is allowed. Come in!"

Your friend: "I'm from Random Inc!" Bouncer: "Not on the list. Sorry!"

CORS is the bouncer for websites!


The Problem

Your website is at mysite.com. You want to load data from api.example.com.

Browser: "Wait! That's a different domain!" Browser: "I'm blocking this for security!"


How CORS Fixes It

The API server says: "It's okay, mysite.com is allowed!"

Browser: "Can mysite.com access this?"
API Server: "Yes, mysite.com is on my list!"
Browser: "OK, I'll allow it."

The server sends a header:

Access-Control-Allow-Origin: mysite.com

Common CORS Error

Access to fetch blocked by CORS policy

This means the server didn't say your site is allowed!

Fix: Server needs to add CORS headers.


In One Sentence

CORS prevents websites from loading data from other domains unless those domains explicitly allow it.


πŸ”— Enjoying these? Follow for daily ELI5 explanations!

Making complex tech concepts simple, one day at a time.

More from this blog

esreekarreddy

132 posts