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

Different hashes for templatedUrls and original file #763

Closed
piehei opened this issue Aug 23, 2017 · 4 comments
Closed

Different hashes for templatedUrls and original file #763

piehei opened this issue Aug 23, 2017 · 4 comments
Labels
Bug An issue with our existing, production codebase.

Comments

@piehei
Copy link

piehei commented Aug 23, 2017

Library Affected:
workbox-build

Browser & Platform:
all browsers

Issue or Feature Request Description:

I use workbox-build as the last step of my gulp process. It's configured like so:

gulp.task('bundle-sw', () => wbBuild.injectManifest({
    globDirectory: './dist/',
    swSrc: './src/service-worker.js',
    swDest: './dist/service-worker.js',
    globPatterns: ['**/*.{html,js,css,woff,woff2,eot,svg,png,json}'],
    globIgnores: ['service-worker.js', 'static\/json\/**'],
    templatedUrls: {
      '/': ['index.html']
    }
})
...

I added templatedUrls as noted here #758 in order to have a workaround for ignoring url parameters (I want to have /?home=1 for home screen adders). However, I noticed that the generated service-worker.js has these entries:

workbox.precache([
  {
    "url": "index.html",
    "revision": "6bafce7795e4c393ccc4d201151a432c"
  },
...
  {
    "url": "/",
    "revision": "ee942f6ef2fcc3a8193ec0c9b4d874af"
  }
]);

Not being completely aware of how the library works this immediately caught my attention. My gut says the hashes should be the same since I think I'm routing everything that tries to hit the '/' route to '/index.html' and dropping all params at the same time.

Is this intentional, and if so, what am I missing here?

Thank you for the great tools.

@gauntface
Copy link

Yeah this feels pretty weird / wrong to me. I'll have a crack at writing a small test case for this and double check the behavior.

Thanks for the bug report :)

@gauntface gauntface added the Bug An issue with our existing, production codebase. label Aug 28, 2017
@jeffposnick
Copy link
Contributor

There's different logic used for generating the hashes for entries in globPatterns vs. entries in templatedUrls.

For globPatterns, we take the MD5 hash of each file.

The templatedUrls logic effectively concatenates all of the individual hashes, and returns a hash of that concatenated string, ensuring that if any of the individual hashes change, the overall hash changes.

The MD5 hash of '6bafce7795e4c393ccc4d201151a432c' is 'ee942f6ef2fcc3a8193ec0c9b4d874af', which explains what you're seeing.

I don't think there's any benefit of adding in special logic to return the underlying hash, instead of the hash-of-hash, when templatedUrls is passed on a single dependency. This amounts to an implementation detail.

@gauntface
Copy link

@jeffposnick Is there an issue here that precaching will cache the index.html file twice (And update twice) in the above example?

@jeffposnick
Copy link
Contributor

Yes, the configuration in #763 (comment) would end up caching index.html twice, once with / as the cache key, and once with /index.html. And then have to keep each up to date.

It's not ideal, and now that the fix for #758 is deployed, it shouldn't be necessary anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug An issue with our existing, production codebase.
Projects
None yet
Development

No branches or pull requests

3 participants