Referrer Policy and Privacy Controls
You'll learn how to control what information your requests reveal about the page they came from, protecting user privacy.
When your browser makes a request—like fetching an image or calling an API—it can include a Referer header (yes, misspelled in the HTTP spec!) that tells the destination server what page you were on. This can expose sensitive information, like internal URLs or search terms in query strings.
What the Referrer Reveals
By default, browsers send the full URL of the current page in the Referer header. If you're on https://yoursite.com/user/12345/private and fetch a resource, the destination server sees that entire path—potentially exposing user IDs, session tokens, or private paths.
Controlling the Referrer
The Fetch API gives you two ways to control this:
1. referrer option: Override what URL appears in the Referer header (or omit it entirely with empty string)
2. referrerPolicy option: Set a policy that determines how much of the URL to send
Common referrerPolicy values:
"no-referrer"– send no referrer at all"origin"– send only the origin (https://yoursite.com), not the full path"strict-origin-when-cross-origin"– full URL for same-origin; just origin for cross-origin (modern default)
Privacy in Action
When calling a third-party API, you might want to hide your internal paths:
fetch('https://api.example.com/data', {
referrerPolicy: 'no-referrer'
});
Or when analytics shouldn't see query parameters but should know the domain:
fetch('https://analytics.com/track', {
referrerPolicy: 'origin'
});
Key Takeaway: Use referrerPolicy to limit what information your requests leak about the user's current page, balancing functionality with privacy protection.