0

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 [SCREENSHOT[1]

Vivek Pratap Singh
  • 9,326
  • 5
  • 21
  • 34
  • It's hard to tell without seeing your service worker code. – Kinlan Jun 28 '16 at 12:13
  • I'm using sw-precache for static resources and also using toolbox for dynamic. Paul, Is this because sw registers in parallel and make network request separately for pre-cached items ? I can share my code with you if you want. – Vivek Pratap Singh Jun 28 '16 at 14:25

1 Answers1

6

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.)

Jeff Posnick
  • 53,580
  • 14
  • 141
  • 167