Replies: 1 comment
-
Hi @gmonking, Thanks for your detailed question! Currently, Next.js 13.5.4 does not provide an official, built-in way to preload CSS files without applying them immediately and then dynamically apply them later via app logic. Why? Preloading CSS without applying it requires changing the rel attribute to preload and then switching it dynamically to stylesheet at runtime, which is a manual process and not natively handled by Next.js. Possible workarounds: Critical CSS + deferred CSS loading CSS-in-JS or dynamic style imports Summary If reducing initial CSS load time and blank screen is a priority, consider critical CSS strategies or dynamic imports combined with client-side style application. Happy to help with example code or alternative patterns if you want! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Background
I'm using Next.js 13.5.4. For performance reasons, I want to preload CSS files (e.g., with ) but not automatically apply them as in the initial HTML.
The goal is to let the browser render a custom loading element in the body as early as possible, and then use JavaScript to load and apply the CSS once my loading screen is shown. This can help improve the perceived performance and reduce the blank screen time.
My Question
Is there any officially supported way in Next.js 13.5.4 to achieve this workflow? Specifically:
Can Next.js output CSS as preload only, and leave it to the app logic to apply the styles?
Are there any built-in APIs, configuration options, or recommended practices to support this pattern?
What I've tried
On the server side, intercepting and modifying the HTML to replace with . But this is a hacky and hard-to-maintain solution.
Additional context
This pattern is important for projects that want to deliver a faster loading experience, especially when CSS bundles are large or device performance is limited.
Any official suggestions, workarounds, or pointers to documentation would be greatly appreciated.
Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions