Comment

David

Why would you do this when you can cache your CSS once, and reuse as necessary across your entire site? Now with this, you have to cache the CSS for every page, or worse, overwrite previously cached files because they use the same filename but have different content.

You're solving a problem that doesn't exist, and ironically, by attempting to optimize, you are unoptimizing because you can't see the bigger picture.

Replies

Peter Bengtsson

It's not as simple as that.

When people visit my site they generally just check out the one page they landed on and then move on to some other site. Actually, Google Analytics tells me my visitors are only visiting 1.17 pages. That means that they get very little benefit to caching the CSS file. Only a fraction of people will benefit.

The benefit however of moving the CSS into the HTML document is that the page loads faster for that one initial load. The "first time impression" will be great!

So, it depends on the nature of your website. Is it an app? Is it a blog? Is it something in between.

And note that people's browsers have limited amount of cache space (especially on mobile devices) so if your visitors only come once a month, many times they return but their browser has forgotten the cached CSS.

And if your visitors refresh the page the external resources are reloaded anyway.