CSScompressor Nederlands

CSS optimization for speed

Minifying is the last and smallest step. The things that actually make a CSS-heavy page feel slow are the number of requests, when those requests happen, and how much of the stylesheet is never used. Here is the order to work in.

1. Get CSS off the critical path

Every <link rel="stylesheet"> in your <head> blocks rendering. The browser will not paint anything until it has fetched and parsed all of them, because a later rule could change everything it has already laid out. Three stylesheets on a slow connection means three round trips before the first pixel.

So: one stylesheet, not five. Concatenate at build time. If you load a font stylesheet from another domain, that is an extra DNS lookup, TLS handshake and round trip on the critical path — self-host the font files instead and the whole chain disappears.

2. Inline the critical CSS

The styles needed to paint what is visible without scrolling — usually 5 to 15 KB — can go directly into a <style> block in the head. The browser then paints immediately, and the full stylesheet loads in the background:

<style>/* critical rules, minified */</style>
<link rel="stylesheet" href="/css/style.css" media="print" onload="this.media='all'">

That media="print" trick makes the request non-blocking; the onload switches it back on once it has arrived. Add a plain <noscript><link …></noscript> as a fallback.

This is the single biggest CSS win available, and it directly improves Largest Contentful Paint. It is also the most work, because you have to determine which rules are critical — tools like Critical or Penthouse can extract them during your build.

3. Delete what nobody uses

On most real sites, well over half of the CSS is never applied to anything. Pull up the Coverage panel in Chrome DevTools (open the command menu with Ctrl+Shift+P and type "coverage") and it will show you exactly how much of each stylesheet went unused on that page.

Common causes, in rough order of size: a whole UI framework loaded for four components, styles for pages that were deleted years ago, and vendor prefixes for browsers that no longer exist. Deleting unused rules beats minifying them by an order of magnitude — one is 50 percent of the file, the other is 20 percent of what is left.

4. Set cache headers properly

A returning visitor should download no CSS at all. Give the file a hashed name (style.8f2a1c.css) and then an aggressive header:

Cache-Control: public, max-age=31536000, immutable

Because the name changes whenever the content changes, a year-long cache is safe. This costs one line of server configuration and is worth more than every other item on this page combined for repeat visits.

5. Turn on brotli, then minify

Brotli compresses CSS roughly 15 to 20 percent better than gzip and every current browser supports it. Most hosting panels have a checkbox; on Apache it is mod_brotli, on nginx brotli on;. Minify after that — with the CSS compressor or in your build — for the last few percent.

The Core Web Vitals your CSS touches

Measure, do not guess

Run PageSpeed Insights on the page you actually care about, look at the field data rather than the lab score if it is available, and fix the item at the top of the list. Then measure again. A score is not the goal; the goal is that the page paints quickly on a mediocre phone on a mediocre connection.

How many stylesheets should a page load?

One, in almost every case. HTTP/2 made extra requests cheaper but not free, and each one is still a render-blocking dependency. Split only when a large chunk of CSS is genuinely needed on a single rarely-visited page.

Is inlining all my CSS a good idea?

Only if the whole stylesheet is small, under roughly 10 KB. Inlined CSS cannot be cached separately, so it is re-sent with every page. Inline the critical part and cache the rest.

Does CSS affect my Google ranking?

Indirectly. Core Web Vitals are part of the page experience signal, and render-blocking CSS is a common cause of a poor LCP. It is a modest factor compared to content and links, but it is real and it is within your control.

What about @import?

Avoid it in production. An @import inside a stylesheet is discovered only after that stylesheet has been downloaded and parsed, so it serialises two round trips where a second <link> would have run them in parallel.

Other tools on this site

Read more