tl;dr; How much web performance negative overhead does including a CSS stylesheet (that you don't use) add to the rendering time? I don't know. But WebPagetest gives us some clues.
To jump straight to the results, checkout this video
which is the slow motion rendering of 1 + 5 pages. Each page has one more big fat CSS stylesheet linked than the other. I.e. the 5th one links to 5 different
.css URLs. There's also a 0th one which only loads 1
.css file which has nothing in it.
I love CSS frameworks and use them ALL the time. But I'm also interested in web performance and using techniques like real-time static analysis to figure out what CSS that doesn't need to be loaded. Some of those techniques surely lead to less stuff needing to be downloaded but how big is the gain? Not sure.
So I made 6 pages that loads a CSS framework but doesn't actually use any of it. The browser will be instructed to download the file and parse it. That takes time and CPU-work will surely will have an effect on the total rendering time.
.css files and one little
.js file which prints something on the DOM. The reason there's a 5 second delay until it uses AJAX (
fetch) to figure out their sizes is because I don't want that effect to affect the rendering on WebPagetest.
Notice that there are two cases of "outliers". According to the measurements,
bloat5.html take shorter time to render compared to their smaller files (
bloat4.html respectively). That seems to indicate that - even though WebPagetest does 3 runs each - that "network I/O luck" plays a big role.
It does have an effect
of reduced web performance. I.e. longer loading time. The page with just 1
.css file takes 0.5 seconds and the one with 5
.css files takes 0.8 seconds. However, the results also indicate that that much of the total time is spent waiting for the download. Once the brower has downloaded the payload, it appears to be very fast at parsing it to get ready to render the page accordingly. In other words, don't worry so much about the "bloat" of the content of the CSS file. Worry more about the excessive HTTP requests needed in total.
It would be interesting to inline every CSS file into the
.html page and re-run. That means only the
.html needs to be downloaded from the network and although the last one will be bigger, when all are gzipped the difference isn't huge.
After publishing this, I decided to inline every
.css as big
<style> tags. For example,
bloat4.html (View source).
What this proves is that the difference we saw earlier was almost entirely due to "network I/O luck". All pages are gzipped. The smallest one is only 0.19Kb and the largest one is 183Kb. But there's no noticable difference in the total time it takes to render these two. Basically, browser's ability to parse CSS is FAST! Don't worry so much about the size of the CSS payload itself. Go forth and make pretty web pages!