Hacker News new | ask | show | jobs
by untog 4573 days ago
Wait, you inline your JS and CSS? Doesn't that mean that the user has to re-download it with every page? I get the desire to have as few connections going as possible, but just be sensible about caching. First page load downloads the CSS + JS, subsequent page loads just serve it from cache.
3 comments

If the majority of your visitors only ever load one page then only the cold-cache scenario matters, and there's plenty of sites where that's the case. Even if your visitors do load multiple pages, if the cold cache load time is fast enough, does it matter that the subsequent pages aren't even faster?

This obviously doesn't work if you're serving up multiple megabytes of CSS+JS, but I suspect they're an order of magnitude or two short of that.

We don't exactly inline the CSS. (Actually, to be perfectly honest, sometimes we do when that seems like the more efficient thing to do and there is no benefit of modularity to be got from CSS.) However, in general we actually construct the HEAD and CSS also through the server library using some logic and parameters.

Now, you are right, this means that from page to page, those 3-4 bytes might be the same and re-downloaded. However, we are focused on mobile phones and some of our user base is on crappy mobile phone browsers (Nokia phones that are still popular here) that have a bad caching system. So the trade off is between 3-4 bytes of CSS that is a repeat, versus a whole new request. And 3-4 bytes of CSS is not even noticeable. A request most defiantly is.

How much CSS can you fit into 4 bytes?

  a {}
Only if it's not gzipped :P That would bulk it up to more like 25 bytes.
Maybe they meant kbytes?
Lol. Sorry KB! My bad!
I agree with this. By inlining all the JS and CSS, you lose the entire benefit of the browser cache, making each HTTP request for a real page a lot larger.
Unless you're using snippets or partial views where you can load only what's needed (in terms of JS and CSS) on a given page.

In that instance, I can see an advantage for inlining it, but it sure doesn't make for attractive code. Priorities though - right?

Even then, unless your partial views are barely ever repeated in different pages it still isn't worth it. And if they're barely ever repeated then there isn't much point in them being partial views.