Open Bug 1527334 Opened 6 years ago Updated 2 months ago

Navigating to a page that was prefetched with <link rel="prefetch"> re-downloads it

Categories

(Core :: Networking: Cache, defect, P3)

65 Branch
defect

Tracking

()

UNCONFIRMED

People

(Reporter: adieulot, Unassigned)

References

(Blocks 2 open bugs)

Details

(Whiteboard: [necko-triaged][necko-priority-next])

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.96 Safari/537.36

Steps to reproduce:

  • Add <link rel="prefetch" href="2.html"> dynamically on a page
  • Click on a link to 2.html

2.html doesn’t have any cache header.

Actual results:

The page got prefetched when the link element was added. When I click on the link the page is downloaded again.

Expected results:

When clicking on the link the page should not be re-downloaded.

Can you please post the http headers for 2.html ?

HTTP/1.1 200 OK
Content-Type: text/html
Date: Tue, 12 Feb 2019 21:27:08 GMT
Connection: keep-alive
Transfer-Encoding: chunked

I think that the caching time is pretty short because the Date header is not far in the past.
I think the document is already expired when you open it.

Component: Untriaged → Networking: Cache
Product: Firefox → Core

Dragana, do you know who on our team knows prefetch the best? I can take a look if you don't.

Matti, your theory is likely correct. I don't recall any enforcement of use in the prefetch code, so this depends on cache reusability setup by the server, probably.

Likely candidate for an INVALID.

Flags: needinfo?(dd.mozilla)

Sorry for not providing the use cases in the first post. I’ll do so now.

The thing is that prefetch requiring cache headers makes it much less useful (and is not what Chrome is doing).

On Chrome’s behavior:
https://medium.com/reloading/preload-prefetch-and-priorities-in-chrome-776165961bbf

prefetch requests are maintained in the unspecified net-stack cache for at least 5 minutes regardless of the cachability of the resource.

So prefetched requests in Chrome are available for 5 minutes after prefetch.

On the usefulness of prefetching without cache headers:
Two recent JS library make sites much faster without a lot of effort in Chrome, using prefetch, and they’re popular.
https://instant.page/ “Make your site’s pages instant in 1 minute” (my library) prefetches on mouseover/touchstart right before a click happens. It was released 5 days ago and got 1200 points on Hacker News.
https://github.com/GoogleChromeLabs/quicklink prefetches links in the viewport. It was released two months ago and amassed 5900 stars on GitHub.

Users really respond to speed (see first footnote on instant.page) and prefetch makes it possible to noticeably improve the user experience very easily, but only for browsers that reuse prefetched requests without cache headers.

We need to do refactoring of prefetch. Currently it depends on cache.

Flags: needinfo?(dd.mozilla)
Priority: -- → P3
Whiteboard: [necko-triaged]

Another use case for this is to make an extension to prefetch pages, like FasterChrome.

Severity: normal → S3

We need to do refactoring of prefetch. Currently it depends on cache.
— April 2019

Has this happened?

Has this been fixed yet? Thank you.

Blocks: necko-perf
Whiteboard: [necko-triaged] → [necko-triaged][necko-priority-review]

I think this is still a problem. I think prefetching a resource for navigation wouldn't work at all right now

Whiteboard: [necko-triaged][necko-priority-review] → [necko-triaged]

For pages that don't have cache headers, we can either have a metadata entry that says it's a prefetch, so we check that when determining if the cache entry is valid, or we can use forceValidFor to force the cache entry to be valid.

Whiteboard: [necko-triaged] → [necko-triaged][necko-priority-next]

(In reply to Alexandre Dieulot from comment #9)

We need to do refactoring of prefetch. Currently it depends on cache.
— April 2019

Has this happened?

Alexandre, thank you for your continued interest in this bug. I am not sure if we will do a full refactor, but might atleast try Valentin's approach in Comment 12.
To understand the priority for this fix, do you have any numbers on how common is for us to get the prefetch requests without cache headers?
Thanks

Flags: needinfo?(adieulot)

(In reply to Sunil Mayya from comment #13)

To understand the priority for this fix, do you have any numbers on how common is for us to get the prefetch requests without cache headers?

The vast majority of prefetch requests are done without cache headers. Prefetching mostly happens through JS libraries (such as my own instant.page, https://github.com/GoogleChromeLabs/quicklink, Flying Pages) that website owners plug simply into their websites, with zero thought towards crafting elaborate cache headers.

Flags: needinfo?(adieulot)
You need to log in before you can comment on or make changes to this bug.