feat: lazy-load non-critical vendor CSS#965
Open
pivaldi wants to merge 1 commit into
Open
Conversation
|
This pull request contains changes to the configuration file. Please make sure the documentation in NexT website is changed or added. |
10 tasks
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.
Motivation
FontAwesome, Fancybox and KaTeX CSS are render-blocking but not needed for
first paint. Loading them eagerly hurts Lighthouse / Core Web Vitals (FCP, LCP)
on pages that don't use them above the fold. This makes those stylesheets
non-render-blocking via opt-in lazy loading.
Changes
New opt-in config (
_config.yml), disabled by default so behavior isunchanged unless enabled:
next_vendorshelper (scripts/helpers/engine.js) accepts an optionsobject with a
lazyflag. Whenlazyis set andperformance.lazy_cssis enabled, the stylesheet is loaded with the standard preload +
onloadswap technique, plus a
<noscript>fallback for JS-disabled clients:JS handling is unchanged (it already uses
defer). Existingintegrity/crossoriginattributes are preserved in both the preload and noscript tags.Templates opt the three non-critical stylesheets in:
layout/_partials/head/head.njk—fontawesome,fancybox_csslayout/_third-party/math/katex.njk—katexNotes
performance.lazy_css: true.next_vendors(name)still works; the options argumentis optional.
Testing
performance.lazy_css: false(default): tags render exactly as before(render-blocking
<link rel="stylesheet">).performance.lazy_css: true: FontAwesome / Fancybox / KaTeX CSS emit thepreload+onloadswap with a<noscript>fallback; styles still applywith and without JavaScript.