Closed patrickkettner closed 7 years ago
+1
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.
Going to the docs
Just a basic caching worker, like this one can greatly speed up a lot of websites.