Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime cache questions and exclude files #1445

Closed
Nooshu opened this issue Apr 23, 2018 · 1 comment
Closed

Runtime cache questions and exclude files #1445

Nooshu opened this issue Apr 23, 2018 · 1 comment

Comments

@Nooshu
Copy link

Nooshu commented Apr 23, 2018

Library Affected:
Workbox 3.1.0, generateSW() with CLI

Browser & Platform:
Chrome 66 (OSX)

Issue or Feature Request Description:
Is it possible to exclude files from the runtime cache? I am trying to exclude gtm.js and analytics.js from the runtime cache but I'm not having much luck. In runtimeCaching I was hoping I could exclude it there using:

runtimeCaching: [{
    urlPattern: /.*/,
    handler: 'networkFirst'
  },
  {
    urlPattern: /gtm.js|analytics.js/,
    handler: 'networkOnly'
  }]

But it doesn't change anything. Is it possible to disable the runtime cache completely?

Out of interest what is the lifespan of the runtime cache? Is it disposed of every time a user closes the browser? Or does it persist like the pre-cache and then look for updates on the next page load?

Thanks for the excellent library!

@josephliccini
Copy link
Contributor

josephliccini commented Apr 24, 2018

Lifespan of runtime cache (I believe) works like this:

  1. You set an expiration on it of N seconds
  2. That cache will persist, even if the user closes their browser, logs out, etc.
  3. If a request is intercepted, and the router associates that request with the cache, then expiration logic is run (i.e. it clears out stale entries for the whole cache)
  4. Otherwise it will persist indefinitely.

I have filed an issue around workbox having an imperative way to delete cache and IndexedDBs (which will also persist) #1365

Also, left some tips and a video link here: #1407

Basically, as the developer of your app, you have to make sure that you own the expiration strategy of your caches, especially if there is anything remotely sensitive or user identifiable (if you would like to respect a user's privacy). Workbox has a lot of great utilities, but ultimately if you don't add your own logic to clear up renamed caches, clear up API schema changes from older API versions, etc. it won't do anything automatically, and you may end up with a cache graveyard in your users browser.

What we did, is that during our worker's 'activate' listener, we do a series of cache cleanups, including manually running the expiration manager (https://developers.google.com/web/tools/workbox/reference-docs/v2.1.3/module-workbox-cache-expiration.CacheExpiration) (NOTE: this is 2.1.3)

That way Cache expiration logic is enforced on each activation of a new worker. But each app will probably have their own expiration strategies that work for them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants