TylorS / snowpack-plugin-hash

Apply content hashes to your production build
15 stars 2 forks source link

Service workers should not be renamed #19

Open teleclimber opened 3 years ago

teleclimber commented 3 years ago

It turns out it's a bad practice to change the filename of service workers. See this:

https://developers.google.com/web/fundamentals/primers/service-workers/lifecycle#avoid-url-change

Currently this plugin changes the names of all JS files, which means it renames service workers too. Would it be possible to specify in the config filenames to ignore?

Thanks.

TylorS commented 3 years ago

Hey @teleclimber, thanks for opening an issue. I didn't know that was a bad practice! Thanks for sharing the link.

Adding some additional configuration for which files to include or not include seems like it would be a pretty well-received changed

teleclimber commented 3 years ago

Yes absolutely.

Would you want to make it open-ended? like glob support to select files to include / not include?

Or would you just have a config that is an array of patterns to ignore? Like:

readonly ignorePatterns?: string[]

The problem with the former is that I think you currently only support JS files, so an open-ended pattern might include non-JS.

The ignorePatterns should be easier to implement and is certainly good enough.

TylorS commented 3 years ago

I think I'd be cool with it being an open-ended include/exclude style. The underlying library, https://github.com/TylorS/typed-content-hash, actually does support plugins to expand the kinds of files it understands and it will just filter out anything it doesn't. By default it currently understands how to parse HTML, CSS, and JS, but only adds hashes to CSS + JS files it finds