Repository navigation
App Router bundles non-critical CSS from other routes into initial page CSS #95167
|
We have a large e-commerce application using the Next.js App Router with a structure similar to: [locale]/
page1/
page.tsx
page2/
page.tsx
...Most routes share a common The issue we are seeing is that CSS from components used in other routes/pages is still getting bundled into the homepage CSS, even when those components are not rendered initially. This increases the amount of non-critical CSS loaded during the first paint. We already tried:
However, the CSS for those lazy-loaded components still appears in the initial CSS bundle. Our goal is to:
Questions:
|
Replies: 3 comments 2 replies
Review: Next.js App Router CSS Chunking — Community Answer Fact-CheckVerdict: Directionally reasonable, but it understates what's actually configurable. The claim "no supported configuration exists" is the weakest part — 1. CSS chunking controlClaim: No supported config to force CSS into separate files or prevent merging. Verdict: ❌ Partially wrong.
const nextConfig = {
experimental: {
cssChunking: 'strict', // try this first
},
}
This is the single biggest gap in the original answer. Test 2. Webpack / custom pluginsClaim: Not supported, may break across releases. Verdict: ✅ Correct. The App Router's CSS pipeline runs through internal loaders/plugins tied to the build, and Turbopack increasingly handles CSS through its own internals that don't route through the standard webpack config at all. A hand-rolled competing extraction plugin is not realistically maintainable long-term. Good practical advice as written. 3. Relation to issue #64773Claim: Yes, closely related. Verdict: ✅ Correct, but worth being precise. The actual fix (PR That's relevant background, but it's narrower than "unrelated component CSS leaking into route bundles" — which is a broader, still-open complaint:
That second report matches the symptom described almost exactly, and it's still being discussed as unresolved in general form. 4. Recommendations (lean layouts, CSS Modules, route groups, dynamic imports)Claim: Reasonable hygiene practices. Verdict:
const nextConfig = {
experimental: {
inlineCss: true, // all-or-nothing; not just "critical" CSS
},
}5. "No officially supported way to load only critical CSS while deferring dynamic component CSS"Verdict: ✅ Correct — this is the honest bottom line. True per-component critical-CSS extraction (à la Critters) is not supported on App Router: the Recommended next steps, in order
|
It is not true that setting cssChuncing: true will reduce css bundle size. |
|
CSS Chunking can intentionally lead to overshipping "unreleated" css to other pages. This is done to reduce the number of requests needed for pages (since they have a cost too). We recently added a new css chunking mode |
CSS Chunking can intentionally lead to overshipping "unreleated" css to other pages. This is done to reduce the number of requests needed for pages (since they have a cost too).
We recently added a new css chunking mode
experimental.cssChunking: { type: "graph" }which adds more options to control the heuristic how much overshipping it accepts.