Skip to content

Commit

Permalink
Add explainer for the referrer_policy key in speculation rules (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
kjmcnee authored Nov 8, 2022
1 parent a15dff7 commit 9a34954
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion fetch.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ One alternative to our sufficiently-strict referrer policy proposal above is to

This would allow pages which otherwise set globally-lax referrer policies, such as `"unsafe-url"`, to perform cross-site preloads. Whereas with our current proposal, such preload requests are ignored.

The main downside of this is that deviates from developer intent. We think it's better to instead [introduce the ability to trigger preloads with a different referrer policy than your document uses](https://github.com/WICG/nav-speculation/issues/167).
The main downside of this is that deviates from developer intent. We think it's better to instead [introduce the ability to trigger preloads with a different referrer policy than your document uses](./triggers.md#explicit-referrer-policy). See [discussion](https://github.com/WICG/nav-speculation/issues/167).

## Using a privacy-preserving proxy

Expand Down
24 changes: 24 additions & 0 deletions triggers.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- [List rules](#list-rules)
- [Requirements](#requirements)
- [Window name targeting hints](#window-name-targeting-hints)
- [Explicit referrer policy](#explicit-referrer-policy)
- [Future extensions](#future-extensions)
- [Scores](#scores)
- [Document rules](#document-rules)
Expand Down Expand Up @@ -177,6 +178,29 @@ Note that if a page is truly unsure whether a given URL will be prerendered into

However, in implementations such as Chromium that need the target hint, this will prerender the page twice, and thus use twice as many resources. So this is best avoided if possible.

### Explicit referrer policy

By default, the referring document's referrer policy is used for the speculative request. The policy to use for the speculative request can be specified in a rule using the `"referrer_policy"` key and the desired referrer policy string.

For example:
```json
{
"prefetch": [
{"source": "list",
"urls": ["https://en.wikipedia.org/wiki/Lethe"],
"referrer_policy": "no-referrer"
}
]
}
```

For speculation actions that would be prevented by the [**sufficiently-strict referrer policy** requirement](./fetch.md#stripping-referrer-information) on a referring page with a lax policy, this allows the referring page to set a stricter policy specifically for the speculative request.

Note that referrer policy matching is not done between the speculative request and the user facing navigation. So given the above rule, a request would be made with `no-referrer` and would still be used even if the user clicked on:
```html
<a href="https://en.wikipedia.org/wiki/Lethe" referrerpolicy="unsafe-url">
```

## Future extensions

### Scores
Expand Down

0 comments on commit 9a34954

Please sign in to comment.