Reputation: 9974
As I'm working on building progressive web apps. We are facing weird behaviour for service worker.
1. Clear cache and unregister service worker
2. Go to www.example.com
3. Examine the network calls for resources (JS/CSS)
Expected result: Only single network request should go for one resource.
Actual result: Two network requests are being made for each of the resource [
Upvotes: 0
Views: 1360
Reputation: 56044
What you're seeing in sw-precache
fetching the resources to populate its caches. That happens independently of the initial request made by the controlled page. It's a fairly common model, whether or not you're using sw-precache
.
(As an aside, I see that you're explicitly versioning your JS and CSS resources, which is great. You'll notice that sw-precache
appends a cache-busting header to its precaching requests right now, meaning that they'll always go against the network instead of the HTTP browser cache. The upcoming 4.0.0 release of sw-precache
, which you can use now via the master
branch, has a new dontCacheBustUrlsMatching
option, which allows you to opt-out of cache-busting for resources that you're explicitly versioning via filenames. Using that option means that the additional sw-precache
request to populate its caches will be fulfilled via the HTTP browser cache, skipping a trip to the network.)
Upvotes: 6