h5bp / html5-boilerplate

A professional front-end template for building fast, robust, and adaptable web apps or sites.
https://html5boilerplate.com/
MIT License
56.46k stars 12.23k forks source link

consider adding a service worker #1689

Closed patrickkettner closed 7 years ago

patrickkettner commented 9 years ago

Just a basic caching worker, like this one can greatly speed up a lot of websites.

jpmedley commented 8 years ago

+1

jeffposnick commented 8 years ago

Integrating with a build-time tool like sw-precache would be more appropriate than using that sample code—I've sprinkled a copious number of comments throughout it like

// If at any point you want to force pages that use this service worker to start using a fresh
// cache, then increment the CACHE_VERSION value. It will kick off the service worker update
// flow and the old cache(s) will be purged as part of the activate event handler when the
// updated service worker is activated.

and

// This sample illustrates an aggressive approach to caching, in which every valid response is
// cached and every request is first checked against the cache.
// This may not be an appropriate approach if your web application makes requests for
// arbitrary URLs as part of its normal operation (e.g. a RSS client or a news aggregator),
// as the cache could end up containing large responses that might not end up ever being accessed.
// Other approaches, like selectively caching based on response headers or only caching
// responses served from a specific domain, might be more appropriate for those use cases.

The approach to service worker generation that the Web Starter Kit project is using (based on sw-precache) could serve as a model. Build-time integration ensures that as a site's static resource change over time, users' caches will be updated efficiently, without additional work from each developer.

roblarsen commented 7 years ago

Going to the docs