1

Specifically, does the browser cache only the text content of the stylesheet — so it doesn't have to fetch it again from the network — or does it also cache an internal representation it has of the contained CSS rules after parsing, so neither fetching nor parsing of a cached file is necessary?

If only the text content is cached, what are the benefits of caching a stylesheet over inlining it (where it cannot be cached)?

2
  • 1
    If browsers cached rendered views I bet they'd need several GB of disk for a single day worth of data. And it'd be pointless to cache assets. Commented Jan 28, 2014 at 12:54
  • Sorry if this is what you understood. With "internal representation" I didn't mean rendered views but more a data structure containing the parsed CSS rules. I edited the question accordingly. Commented Jan 28, 2014 at 13:12

1 Answer 1

0

Caching is aimed at reducing load time by replacing the typically slow network download with the typically fast local file reading. As such, is a generic solution (you can cache any kind of asset, from HTML to CSS, JavaScript, PDFs, Excel...) and it can accomplish great time savings (normally seconds, even minutes for really slow networks). It also plays well with dynamic HTML.

What you propose is a very specific caching solution for a very specific data set (the nodes of an HTML document together with the CSS rules that apply to them) that typically needs milliseconds to process and can be continually changing thanks to JavaScript. It looks really difficult to implement, it'll be confusing for dynamic sites (when a page loads, everybody expects to get the initial HTML state, not whatever you were doing last time) and there's hardly any benefit on it. I'm not aware of any browser that has even tried it. There're certainly JIT compilers for JavaScript code, but nothing remotely similar to this.

If only the text content is cached, what are the benefits of caching a stylesheet over inlining it (where it cannot be cached)?

I'd say cache itself is a valid benefit, isn't it? Generating inline CSS means more work for the webmaster (you either need to write server-side code that injects CSS files or enjoy the maintenance mess of not even having them). It also increases the size of HTML documents.

Sign up to request clarification or add additional context in comments.

2 Comments

Sorry if my language is confusing. I'm not proposing to cache the HTML nodes along with their CSS style, that would be pretty useless as you already mentioned. I was just wondering if the browser remembers what's "in" the stylesheet instead of the unprocessed state. Much like you remember the plot of a book without having to read it again (even if you were really fast at reading).
Well... Whatever the details are, parsing CSS doesn't take as long as to make it worth it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.