-
Notifications
You must be signed in to change notification settings - Fork 68
feat: improved script warmup #302
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The latest updates on your projects. Learn more about Vercel for Git βοΈ
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
π Linked issue
#294,
#293,
β Type of change
π Description
Current warmup behavior is a bit crude, this PR aims to improve the stability of it while also exposing end user config for more advance use cases.
Background
Nuxt Scripts will insert relevant warmup
link
tags to optimize the loading of your scripts. Optimizingfor the quickest load after Nuxt has finished hydrating.
For example if we have a script like so:
This code will load in
/script.js
on theonNuxtReady
event. As the network may be idle while your Nuxt App is hydrating,Nuxt Scripts will use this time to warmup the script by inserting a
preload
tag in thehead
of the document.The behavior is only applied when we are using the
client
oronNuxtReady
Script Triggers.To customize the behavior further we can use the
warmupStrategy
option.warmupStrategy
The
warmupStrategy
option can be used to customize thelink
tag inserted for the script. The option can be a functionthat returns an object with the following properties:
false
- Disable warmup.'preload'
- Preload the script, use when the script is loaded immediately.'preconnect'
or'dns-prefetch'
- Preconnect to the script origin, use when you know a script will be loaded within 10 seconds. Only works when loading a script from a different origin, will fallback tofalse
if the origin is the same.All of these options can also be passed to a callback function, which can be useful when have a dynamic trigger for the script.
warmup
The
warmup
function can be called explicitly to add either preconnect or preload link tags for a script. This will only work the first time the function is called.This can be useful when you know that the script is going to be loaded shortly.