Limit prefetching of rel="next" documents
Categories
(Core :: Networking, defect, P5)
Tracking
()
People
(Reporter: cmiller, Unassigned)
References
Details
(Whiteboard: [prefetch][necko-would-take])
Attachments
(1 file)
|
6.30 KB,
patch
|
Details | Diff | Splinter Review |
Comment 1•24 years ago
|
||
Comment 2•24 years ago
|
||
Comment 4•24 years ago
|
||
Comment 5•24 years ago
|
||
Updated•23 years ago
|
Comment 6•23 years ago
|
||
Comment 7•22 years ago
|
||
Comment 8•20 years ago
|
||
Comment 9•17 years ago
|
||
Comment 10•15 years ago
|
||
Comment 11•15 years ago
|
||
Comment 12•15 years ago
|
||
Comment 13•15 years ago
|
||
Comment 14•15 years ago
|
||
Comment 15•15 years ago
|
||
Comment 16•11 years ago
|
||
Updated•10 years ago
|
Comment 17•10 years ago
|
||
Comment 18•9 years ago
|
||
Updated•4 years ago
|
Updated•2 years ago
|
Comment 19•2 days ago
•
|
||
Attached is a patch that stops Firefox from prefetching rel=next targets and treats them as preconnect hints instead.
Why
The HTML Standard no longer singles out prefetch for rel=next. The current text
(https://html.spec.whatwg.org/multipage/links.html#link-type-next) says:
"When the next keyword is used with a link element, user agents should
process such links as if they were using one of the dns-prefetch, preconnect,
or prefetch keywords. Which keyword the user agent wishes to use is
implementation-dependent; for example, a user agent may wish to use the
less-costly preconnect processing model when trying to conserve data, battery
power, or processing power [...]"
Firefox currently always picks prefetch, which costs the site a full document
request for every page view that carries a rel=next link. That is the complaint
in comment 0, comment 10 and comment 16, and it is still being hit today:
Datasette removed its rel=next Link header from all HTML pages in 2026 to stop
Firefox fetching the next page of every table
(https://github.com/simonw/datasette/issues/3046).
Picking preconnect keeps us within the spec's "should" while sending no HTTP
request for the next document. Authors who do want the document fetched can
still say so with rel=prefetch, which is unchanged.
What the patch does
- HTMLLinkElement::TryDNSPrefetchOrPreconnectOrPrefetchOrPreloadOrPrerender:
rel=next no longer reaches nsIPrefetchService; it takes the same path as
rel=preconnect (Document::MaybePreconnect). - nsContentSink::ProcessLinkFromHeader: same change for Link response headers.
- New mochitest netwerk/test/mochitests/test_rel_next.html (with rel_next.sjs)
checks that both <link rel=next> and a Link: rel=next header trigger a
speculative connection and do not enqueue a prefetch.
This also removes an inconsistency between the two paths. The element path
passed aExplicit=false for rel=next, so URLs with a query string were skipped
(the workaround suggested in comment 2). The header path went through
nsContentSink::PrefetchHref, which always passes aExplicit=true, so a
rel=next Link header was prefetched even with a query string. That is why the
Datasette URLs (?_next=...) were fetched.
Testing
Local Linux x86_64 build of current main:
- new test_rel_next.html and existing test_rel_preconnect.html pas
- existing prefetch mochitests pass: dom/base/test/test_link_prefetch.html,
dom/base/test/test_bug1268962.html,
dom/tests/mochitest/webcomponents/test_link_prefetch.html,
netwerk/test/mochitests/test_prefetch_cache.html and
test_prefetch_cache_no_headers.html - browser tests pass: browser_page_load_event_prefetch.js,
browser_prefetch_data_usage.js, browser_prefetch_delivery_type.js,
browser_speculative_connection_link_header.js - ./mach lint is clean on the changed files
Not done: no try push and no WPT run, and I have not confirmed the new test
fails on an unpatched build.
Follow-ups, not in this patch
- With this change every caller of nsIPrefetchService.prefetchURI
aExplicit=true, so that parameter and the query-string check in
nsPrefetchService::Prefetch are dead code. I left them alone to keep this
patch to the behaviour change; happy to remove them here or in a follow-up. - The network.prefetch-next pref name and its comment in all.js still describe
rel=next prefetching. The pref continues to gate rel=prefetch.
Alternatives considered
- The Referer/rel=prev heuristic from comment 0 is also allowed by the spec
("heuristic analysis of past user behavior"), but it is more code and more
ways to guess wrong for little gain over preconnect. - Ignoring rel=next entirely (comment 12, comment 14) would go against the
spec's "should".
Description
•