Performance

perf/css-no-import

Shipped CSS does not chain stylesheets with @import; link them in the HTML or combine them in a build.

moderatestaticfe-perf-delivery

Why

The browser finds an @import only after it has downloaded and parsed the stylesheet that contains it, so each import adds a round trip before the page can render. On a mobile connection that is easily several hundred milliseconds of blank screen.

Fix

List each stylesheet with <link rel="stylesheet"> in <head> so they download in parallel, or let a build tool inline the imports into one file. Cascade layers work with links too: @layer reset, components; in the first file, then @layer components { … } in the others.

Examples

/* bad: main.css */
@import url("reset.css");
<!-- good -->
<link rel="stylesheet" href="/css/reset.css">
<link rel="stylesheet" href="/css/main.css">

Sources

Facts

Id
perf/css-no-import
Severity
moderate
Check
static checked in the source by audit
Applies to
css html
Only in projects with
html
Taught by the skill
fe-perf-delivery JavaScript, CSS and asset delivery
Since version
0.1.0

Rule file on GitHub

Read it in the terminal

npx github:dawidolko/frontend-skills explain perf/css-no-import