filter · CSS filters
Flatten CSS @imports (flatten_css_imports)
- Category:
- CSS
- CoreFilters:
- Yes
- OptimizeForBandwidth:
- No
- Risk:
- Generally safe
Replaces CSS @import rules with the contents of the imported file. Eliminates round trips caused by import chains. The CssFlattenMaxBytes parameter (default: 1024000) limits the size of the resulting flattened CSS.
How it works
Flattening is trickier than plain concatenation — media queries, charset rules, and relative URLs all have to survive the merge; see flattening CSS @imports for the edge cases.
When to use it
- In CoreFilters, the default RewriteLevel: it runs unless you disable it.
- Risk rating on these docs: Generally safe.
Risks
The
CSS filters
page lists no specific risks for this filter.
If a page misbehaves with it, DisableFilters flatten_css_imports turns it off for
the scope you set it in.
Configuration
Enable it in the module configuration, at server, virtual-host or location scope:
Apache
ModPagespeedEnableFilters flatten_css_importsnginx
pagespeed EnableFilters flatten_css_imports;IIS (pagespeed.config)
pagespeed EnableFilters flatten_css_importsIt is on by default under CoreFilters; to turn it off:
ModPagespeedDisableFilters flatten_css_imports # Apache
pagespeed DisableFilters flatten_css_imports; # nginx
pagespeed DisableFilters flatten_css_imports # IISOn the worker
The worker runs its own pipeline, configured by flags. Its equivalent of this filter
is the
css import flattening
transform. Toggleable via --no-css-import-flattening.
Scoping, ForbidFilters and the thresholds filters read:
Choosing filters
.
Live example
Replaces @import rules with the imported CSS to avoid chained requests.
This filter changes how the page is structured or delivered, not its size, so the example shows a source diff rather than a byte or request reduction.
Frequently asked questions
- What does the flatten_css_imports filter do?
- Replaces CSS
@importrules with the contents of the imported file. Eliminates round trips caused by import chains. TheCssFlattenMaxBytesparameter (default: 1024000) limits the size of the resulting flattened CSS. - Is flatten_css_imports enabled by default?
- Yes.
flatten_css_importsis in CoreFilters, the default RewriteLevel, so it runs unless you turn it off withDisableFilters. - How do I turn off flatten_css_imports?
- Add
ModPagespeedDisableFilters flatten_css_importson Apache orpagespeed DisableFilters flatten_css_imports;on nginx. On IIS, addpagespeed DisableFilters flatten_css_importsto pagespeed.config.
Related filters
- combine_css — Combine CSS
- compute_critical_css — Compute critical CSS
- extend_cache_css — Extend cache for CSS
- fallback_rewrite_css_urls — Fallback CSS URL rewriting
- inline_css — Inline CSS
- inline_google_font_css — Inline Google Fonts CSS
- inline_import_to_link — Convert @import to link
- move_css_above_scripts — Move CSS above scripts
This page is drawn from the flatten_css_imports entry on CSS filters. Every filter in one table: PageSpeed filters.