-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
ResourceHints Link
header in HTTP 200
#30758
Comments
This could also help generate |
Working on a module version in the meantime. It is likely to be less performant than a baked in feature but should have no user performance impact when using SSG. |
Page load performance increase could be significant if the page contains large style elements in the head before links to additional resources. Without the resource hints, the browser would have to download and read past the inline styles before discovering additional resources to fetch, missing the opportunity to download and read resources simultaneously. While this example assumes the server and browser support content streaming, a saving could still be made before the browser parses the document. |
Will implement as module for the SSG support. Although the simple change for Link headers for SSR in the first issue comment could provide some value in the meantime (possibly JS only). Both can be achieved with a module, SSG is much tricker as the build to route rules logic is more complex. |
Good news, here is an implementation of the module to test: |
This comment has been minimized.
This comment has been minimized.
Added important edit to last comment. Having now tested without network throttling and more powerful hardware the results are minimal potentially may interrupt the browser scheduling by using There may be still an argument for poorer network connectivity like the example image show, such as Note that the browser (Chromium based) would throw console warnings for Note while it appears multiple network requests are made for the same resource, this appears to only be present on the client side and doesn't show in the logs of HTTP server used. Firefox appears to ignores the |
Updated the module again. Performance uplift is available in Chromium based browsers consistently in a test project of at least TestsUsing a local project, test with headers from the module include and excluded.
LCP without module:3G Network throttling![]() LCP with module:
OR
No render blocking resources 3G Network throttling![]()
ConclusionWhile a It is recommended that you conduct your own tests before using this module in production. |
@coderabbitai summerise |
Tip For best results, initiate chat on the files or code changes. @IO-Fire Here's a summary of the discussion: The proposal started as a core Nuxt feature to add resource hints via Link headers in HTTP 200 responses, potentially working with Cloudflare Pages' Early Hints (HTTP 103). It was subsequently implemented as a module (nuxt-resource-hints) to support both SSR and SSG. Performance testing revealed:
The module provides a practical solution for improving page load performance, particularly beneficial for users on slower connections, though gains are modest on fast networks. (`・ω・´)ゞ |
Success! Cloudflare is generating 103 Early hints from the link header: This also works for pages proxied to custom domains. |
Considering the simplicity of the nuxt-resource-hints module, it may be possible to create a Nitro module to benefit other projects using Nitro. |
Describe the feature
Adds a
Link
header from the renderer to give the browser hints in theHTTP 200
response of additional resources while downloading / parsing the server response payload. The intention is to decrease page load time by allowing the browser to simultaneously request upcoming resources needed by the DOM before they are identified.If the browser or any proxies don't support
HTTP 103
Early Hints, then including hints in the laterHTTP 200
still provides early notice. Implementing the feature should hopefully be of minimal operating disruption compared to adoptingHTTP 103
while providing some of the benefits.Anecdotal evidence suggests that unloaded CSS files are blocking the client side loading of pages until fetched as a subsequent resource in Lighthouse testing. Hints may reduce page load time by reducing the gap between the resource identified and render awaiting resource including JS and CSS.
Feedback and suggestions are welcome!
Example of how it could initially work:
main...IO-Fire:nuxt:feature/write-link-header
Although this implementation appears to only show JS and not styles (test sample size of 1). This may also impact the current
103
early hints feature.SSG Support
Update the route rules' headers for each page before the creating completing the route rendering.
OR
May require changes in the Nitro static presets to encompass the headers being identified at render time rather than at route creation.
Header rule limits
Some hosting providers including Cloudflare Pages have limits on headers.
Cloudflare Pages limits the total number of "header rules" similar to route rules.
100 pages / routes with headers would use 100 headers rules. This may limit the number of pages within a site without workarounds such as Baroshem/nuxt-security#504 (comment)
Module Implementation
Module implementation may not be possible as access to the render's data may not be exposed to a module.
Additional information
Final checks
The text was updated successfully, but these errors were encountered: