Origin Components: Scheme, Host, and Port
You'll learn exactly how browsers determine if two URLs belong to the same "origin" — the foundation of web security boundaries.
What Is an Origin?
In web security, an origin is like your home address — it uniquely identifies where content comes from. An origin consists of three parts extracted from a URL:
- Scheme (protocol):
httporhttps - Host (domain):
example.comorapi.example.com - Port:
80,443,8080, etc.
These three components together define the security boundary. If any of them differ between two URLs, they're considered cross-origin.
Same-Origin Examples
Both URLs below share the same origin:
https://example.com/page1https://example.com/api/data
Origin: https://example.com:443 (port 443 is default for HTTPS)
Cross-Origin Examples
Each of these is different origin from https://example.com:
http://example.com— different scheme (http vs https)https://api.example.com— different host (subdomain matters!)https://example.com:8080— different port (8080 vs default 443)https://example.org— different host (different domain)
Why This Matters
The Same-Origin Policy uses these components to decide whether JavaScript from one page can access data from another. Two pages are either "same team" (same origin) or "strangers" (cross-origin). The path (/page1 vs /api/data) and query strings don't affect origin — only scheme, host, and port matter.
Think of it like building security: scheme is the building type (secure vs unsecure), host is the street address, and port is the specific entrance. All three must match for full access.
Key Takeaway: An origin is defined by exactly three components: scheme, host, and port. If any differ, two URLs are cross-origin and face security restrictions.