Skip to content
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

Fallback to <script> loading behavior when preload is not supported #5744

Merged
merged 3 commits into from
Nov 26, 2018

Conversation

timneutkens
Copy link
Member

Based on #5737 (comment)

This will cause a warning in chrome/safari after 3s

@timneutkens timneutkens changed the title Fall back to loading page with onload when preload is not supported Fallback to <script> loading behavior when preload is not supported Nov 26, 2018
@yoavweiss
Copy link

This will cause a warning in chrome/safari after 3s

Regarding the warning, its purpose is to avoid cases where people excessively preload content and do not use it afterwards. Happy to consider alternatives that would still maintain this goal, while enabling the use-case of same page speculative preloading.

@timneutkens
Copy link
Member Author

timneutkens commented Nov 26, 2018

@yoavweiss, so the way this currently works in terms of scripts:

  • Next.js runtime / router / etc
  • Commons chunk, if a module is used in 50% of all pages it's considered commons
  • Script bundle per page

Now on server-side render we add <link rel="preload"> for these 3 scripts, they are all needed to instantiate the interactive page (React hydration)

Then there is <Link href="/path/to/route" prefetch> which is a preloading mechanism for subsequent pages (separate from the current route) built into our router. That feature is what this PR is about.

Previously we would inject <script async src="/pages/something.js"> which kept the spinner going until the page was loaded because all async scripts are waited for like that.

So this PR changes it to inject only the <link rel="preload"> when supported, so that the spinner is not blocked.

@timneutkens
Copy link
Member Author

timneutkens commented Nov 26, 2018

I think showing the warning makes sense in a way, since it forces users to think about what they're prefetching. We just need to document very clearly that the warning is safe to be ignored.

@timneutkens timneutkens merged commit 9d30e41 into vercel:canary Nov 26, 2018
@timneutkens timneutkens deleted the add/improved-prefetch branch November 26, 2018 22:58
@timneutkens
Copy link
Member Author

Going to ship this to canary

@lock lock bot locked as resolved and limited conversation to collaborators Nov 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants