-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
<link rel="prefetch"> downloads aren't persisted as expected — use XHR to save #12800
Comments
A working code sample: <html>
<head>
<link
rel="prefetch"
as="image"
href="https://images.pexels.com/photos/248797/pexels-photo-248797.jpeg"
onload="fetch('https://images.pexels.com/photos/248797/pexels-photo-248797.jpeg')"
/>
</head>
<body>
<h2>Just testing a trick</h2>
</body>
</html> |
So the logic here is..
If we can do further analysis on how well this holds up, it might work. cc @yoavweiss as a sanity check. |
A few questions:
|
Thanks for all the information! I agree with @yoavweiss on `What is your use-case for prefetching images? unsure if it's a big deal to show op placeholder images on navigation? Also won't service worker be able to save it to cache? |
We want to prefetch images so they show up sooner :-) When you click between pages on a Gatsby site, most of the page renders immediately but images don't as they're not discovered until the page is rendered. We want to add the ability to Gatsby to mark images as "critical" so they we can prefetch them. A good example of images loading late is this recently launched Gatsby site https://www.prima.co — try clicking between pages and you get a blinking effect when images load instead of a nice smooth single render. This RFC I posted is related: gatsbyjs/rfcs#35
I haven't seen instances of this (though I also haven't been looking) but if prefetching does follow cache-control headers then we're actually probably fine.
Hmmm that's disappointing...
Yeah we can do this — we do add some prefetches to the |
Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open! Thanks for being a part of the Gatsby community! 💪💜 |
So the problems with subresource prefetching are:
Are you actually navigating between those pages? Or are those "soft navigations"? Otherwise, I guess we can make subresource prefetches that are destined for same origin with same SW scope work. Would require some opt-in though, so I want to make sure the use-case is there. |
Hey again! It’s been 30 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it. Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing! Thanks again for being part of the Gatsby community! |
In Gatsby v2 we shifted to using
<link rel="prefetch">
to prefetch resources as it allows the browsers to be smarter about sharing network bandwidth between competing downloads as it can deprioritize our prefetching when there's higher priority API calls / image requests / etc.One of our assumptions when we made this design decision was that resources we prefetch would well, stay prefetched. So we could prefetch a resource at the start of a session and if it was only used at the end of the session, the browser would keep it around.
I'd asked @addyosmani to review my image prefetching RFC and he mentioned prefetching can be problematic as browsers actually only keep prefetched resources around for ~5 minutes.
Which means that if a user stays on a page for 5+ minutes before clicking onto another page, the browser will need to download the next pages resources again doubling the downloaded bytes and causing extra latency when changing pages.
So we want to keep using
<link rel="prefetch">
as it's the friendliest prefetch but we need to persist the prefetched resources.One way we could do this is to use the onload event to trigger an immediate xhr which would then make the browser persist the resource e.g.
<link rel="prefetch" as="image" href="http://example.com/image.png" onload="fetch('http://example.com/image.png')">
The image will be already be in the memory cache so the browser will just copy it into the more permanent cache (don't remember off top of my head the names of the different browser caches).
The text was updated successfully, but these errors were encountered: