Optimize preload response headers to prioritize critical assets#10612
Merged
Optimize preload response headers to prioritize critical assets#10612
Conversation
changelog: Internal, Performance, Optimize preload response headers to prioritize critical assets
mitchellhenke
approved these changes
May 13, 2024
Contributor
Author
For future consideration: Thinking that since we control most asset rendering through This could also have a few more optimizations:
|
zachmargolis
approved these changes
May 13, 2024
Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>
This was referenced May 17, 2024
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
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.
🛠 Summary of changes
Updates asset rendering in common layouts and critical paths to optimize loading and deprioritize non-blocking assets.
Specifically:
nopushfrom preload headers (related resource, related documentation) (c57441e)These changes stem from a discovery that Rails (as of ActionView 7.1) caps
linkpreload headers at 1kb. Since we aggressively split assets into small stylesheets and scripts, we currently exceed this limit, and therefore some assets are not preloaded using the response headers.For example,
application-*.jsis not included as a preloaded asset in production today, despite being common to every page of the application and controlling critical, high visibility UI elements.It may be possible to configure or override the default value, though it is currently configured as a module constant
ActionView::Helpers::AssetTagHelper::MAX_HEADER_SIZE. The changelog note about "diminishing returns" is a valid consideration as well., though further analysis is required.In the meantime, the changes here are intended to eliminate some low-hanging fruit for more granular control over preloaded assets.
📜 Testing Plan
curl -I --silent http://localhost:3000 | grep linkObserve:
nopushanywhere in the headerdap,session-expire-session, andplatform-authenticator-availableare not included in the headerapplicationis included in the headerPublicSans-BoldandPublicSans-Regularare preloaded as root-relative paths rather than fully-qualified URLsExample:
Before:
After: