←back to thread

260 points gherkinnn | 1 comments | | HN request time: 0.201s | source
Show context
mh-cx ◴[] No.42164537[source]
I wonder why the article doesn't mention utilizing the browser cache for your static CSS and JS assets instead of introducing a service worker as first measure.

Few years ago I built a shopping site MPA this way and the page transitions were almost not noticable.

replies(7): >>42164573 #>>42164584 #>>42164743 #>>42168597 #>>42169927 #>>42170948 #>>42173755 #
jdsleppy ◴[] No.42164573[source]
Same (but not a shopping site). Bundle the JS and CSS into one file each and cache it forever (hash in the filename to bust the cache). Then with each page transition there's exactly one HTTP request to fetch a small amount of HTML and it's done. So fast and simple.
replies(3): >>42164678 #>>42166335 #>>42166710 #
wmfiv ◴[] No.42166335[source]
This has been the common/best practice for so long I don't understand why TFA is proposing something different.
replies(1): >>42170996 #
youngtaff ◴[] No.42170996[source]
Cache control directives indicate how long a browser, proxy etc can store a resource for… they don’t guarantee they will store it for that long though

Control over Service Workers cache lifetime is more explicit

I’d still specify ‘good’ cache lifetimes though

replies(1): >>42173250 #
wmfiv ◴[] No.42173250[source]
Makes sense as a theoretical problem. Have you ever seen data that suggests it's a practical problem? Seems like one could identify "should be cached forever but wasn't" using etag data in logs.
replies(1): >>42176049 #
youngtaff ◴[] No.42176049[source]
Facebook did a study about ten years or so back where they placed an image in the browser cache and then they checked how long it was available for… for something like 50% of users it had been evicted within 12hrs

If one of the most popular sites on the web couldn’t keep a resource in cache for long then most other sites have no hope, and that’s before we consider that more people are on mobile these days and so have smaller browser caches than on desktop

replies(1): >>42177674 #
jeeeb ◴[] No.42177674[source]
From the discussion above it seems that browsers have changed their behaviour in the last 10 years based on that study.

See: https://news.ycombinator.com/item?id=42166914

replies(1): >>42186625 #
1. youngtaff ◴[] No.42186625[source]
Browsers have finite cache sizes… once they’re full the only way to make space to cache more is to evict something even if that entry is marked as immutable or cacheable for ten years