Skip to content
This repository has been archived by the owner on Nov 20, 2019. It is now read-only.

Compute filename with [hash] pattern according to asset-path plugin #39

Closed

Conversation

celiolatorraca
Copy link

Giving possibility to use webpack asset-path plugin pattern in filename.

So that we can now use patterns like:

new ServiceWorkerPlugin({
  entry: path.join(rootDir, 'src/client/service-worker.js'),
  filename: 'sw-[hash:7].js'
}),

I've used html-webpack-plugin as reference (https://github.com/jantimon/html-webpack-plugin/blob/62c9e70113cbd921a9ca8d470cc7a149e361d0e9/lib/compiler.js#L80).

@oliviertassinari
Copy link
Owner

oliviertassinari commented Jul 19, 2017

@celiolatorraca Why would you what to implement such pattern? Service worker files shouldn't be cached. As far as I know, it's a bad pattern to have the service worker name change over time.

@oliviertassinari
Copy link
Owner

You can read this thread for more detail: NekR/offline-plugin#127.

@celiolatorraca
Copy link
Author

Thanks for those links explaining why it is a bad pattern changing SW file name.

This one was the most helpful (https://developers.google.com/web/fundamentals/instant-and-offline/service-worker/lifecycle#avoid_changing_the_url_of_your_service_worker_script).

The idea here was that all my assets are hosted in a CDN, but SW has to be served on our own domain. So, I've tried to use [hash] pattern to update SW script file when changed. With that, I would be able to apply cache as my other assets.

But that's the problem. Every different SW URL is considered a new SW registration...

I'm closing this PR, thanks for your time!

@oliviertassinari
Copy link
Owner

What do you think of adding a warning if such pattern is detected with your ressource?

@celiolatorraca
Copy link
Author

What you mean by adding a warning?

Probably I'll have to serve this file through my server instead of serving it from CDN. Even worse with no cache... Leaving SW to handle its update.
My application is entirely based on caching assets and xhrs. Probably I'll have to upscale a little my infra to do so.

@oliviertassinari
Copy link
Owner

We could warn when someone try to use [hash. I guess it's a common enough pattern in webpack to see people trying to use it.

@celiolatorraca
Copy link
Author

Ohh see!

Good idea! I can send you a PR with this improve if you want...

@oliviertassinari
Copy link
Owner

I would love that :)

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

Successfully merging this pull request may close these issues.

2 participants