←back to thread

260 points gherkinnn | 1 comments | | HN request time: 0s | source
Show context
jonahx ◴[] No.42165501[source]
Can someone explain what the service worker strategy accomplishes that plain old http Cache headers don't? It saves a (almost zero weight) network roundtrip, but feels like it's re-inventing the entire wheel for that small (I think) optimization? Am I missing something?
replies(6): >>42165572 #>>42165591 #>>42165649 #>>42165780 #>>42165856 #>>42166137 #
EionRobb ◴[] No.42166137[source]
For a multi-page app, one of the important uses of serviceworkers is pre-loading and caching resources that aren't on the first page. eg you might have a background image that's only displayed three pages deep but can download and cache it as soon as the site is open.

You can potentially use http2 push to send down files from the server early but I've seen the browser drop the files if they're unneeded for that page load.

Yes, there are other hacks you could do to make the browser download the resources early, like invisible images or preload audio files, but if you're going down that path why not put in a service worker instead and have it download in the background.

replies(3): >>42166608 #>>42168719 #>>42169312 #
1. jeroenhd ◴[] No.42166608[source]
Unfortunately HTTP/2 push is basically dead. Very few sites made use of it and Chrome removed it: https://developer.chrome.com/blog/removing-push