GoogleChromeLabs / sw-toolbox

[Deprecated] A collection of service worker tools for offlining runtime requests
https://developers.google.com/web/tools/workbox/guides/migrations/migrate-from-sw
Apache License 2.0
3.62k stars 332 forks source link

May I read package file for CACHE VERSION #257

Closed mazipan closed 6 years ago

mazipan commented 6 years ago

I add var CACHE_VERSION = '-v1.0.0' in my sw.js But may I read this version from package.json ?

gauntface commented 6 years ago

I'm sorry, I dont understand your question or what you are trying to do.

jeffposnick commented 6 years ago

sw-toolbox is a library, with code that executes at runtime in the browser. You're not going to have access to your local package.json file in that context.

If you need to version caches or resources based on the context of your package.json, it sounds like you would be better served by using a library that integrates with your build process and generates an appropriate service worker file based on your local filesystem.

sw-precache is one such library that works alongside sw-toolbox, and a newer option is using Workbox (which would fully replace sw-toolbox).