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

Change dest folder for the Lib-file #698

Closed
dertuerke opened this issue Jul 24, 2017 · 3 comments
Closed

Change dest folder for the Lib-file #698

dertuerke opened this issue Jul 24, 2017 · 3 comments

Comments

@dertuerke
Copy link

Library Affected:
workbox-sw, workbox-build, etc.

Issue or Feature Request Description:
Can i change the "importScript" copy path with the gulp-workbox?
actually this path generated
importScripts('workbox-sw.prod.v1.1.0.js');

but i want this
importScripts('build/workbox-sw.prod.v1.1.0.js');

@jeffposnick
Copy link
Contributor

If you need that flexibility, I would recommend using the [injectManifest()])(https://workboxjs.org/reference-docs/latest/module-workbox-build.html#.injectManifest) method during your build process, instead of generateSW() (which is what I assume you're using now).

You can pass in the service worker file that was previously generated as the source swSrc option in injectManifest(), after you modify it to include the path to the workbox-sw import that you'd prefer.

If you go this route, then you should remove the actual listing of URLs/revisions from the workboxSW.precache([<url/revision pairs>) call in your swSrc, and instead replace it with the placeholder workboxSW.precache([]). The contents of the array will be automatically populated whenever you call injectManifest().

@dertuerke
Copy link
Author

@jeffposnick thx for the help.

I have another question.

I change my code to "inject manifest" and set my custom path to the lib.
Why has the JS-File so bad naming: workbox-sw.dev.v1.1.0 and workbox-sw.prod.v1.1.0???

If an update comes out, then you have to adjust each time the version number and this is not really optimal.

I mean, it would be enough if the file naming is workbox-sw.prod.js or workbox-sw.dev.js.

@jeffposnick
Copy link
Contributor

Including a version number in the path is a requirement due to the way caching of importScripts() behaves. As of right now, browsers will not re-fetch a resource with the same URL pulled in via importScripts(), regardless of what HTTP caching headers you use, and regardless of whether the script that calls importScripts() changes or not.

So if we didn't include the version number in the filename, the URL /path/to/workbox-sw.prod.js would be downloaded once when the SW is first installed, and then you'd be unable to update existing users by redeploying a new version at the same /path/to/workbox-sw.prod.js URL.

This behavior will hopefully change in the future; see w3c/ServiceWorker#893 for more detail about the planned changes. As browsers start implementing those changes, we'll revisit the recommendations library versioning.

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