Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> The service worker below caches the HTML and CSS that's needed to render the page.

Why would you need a service worker for this? Doesn't the regular browser cache achieve the same thing?



With a service worker, you can stream the header part of a new document instantly from the service worker, while fetching the content. That essentially makes an instance first paint.

I don't think that's what the example is showing, though.


Oh interesting, I didn't know about stitching the streams together in the service worker!

Do you know what the advantage of that is over serving the full cached HTML page layout and then fetching the content HTML from inside the page?


That's a good point, I didn't consider having the browser cache the document. That means you can achieve the same thing with the HTTP cache. (I'm not sure if the retention logic between the service worker cache and the HTTP cache differs much.)

Service workers give you more control about what's in the cache, for example you can serve a stale version of the HTML and then fetch an up-to-date version in the background. But since last year you can also use `Cache-Control: max-age=1234, stale-while-revalidate=86400`, so it should be possible with the HTTP cache as well now.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: