GoogleChromeLabs / css-triggers

A reference for the render impact of mutating CSS properties.
https://csstriggers.com/
Apache License 2.0
899 stars 70 forks source link

SW: New static cache do not get cache #25

Closed oldergod closed 8 years ago

oldergod commented 8 years ago

Via the PR #24 I added new files to the static cache here: https://github.com/GoogleChrome/css-triggers/pull/24/files#diff-c0d537be4c9b8578091846d7aa37044bR33

But as you can see in the sw.js code ( https://github.com/GoogleChrome/css-triggers/blob/master/src/scripts/sw.js#L49 ) , regardless of the version, if the STATIC_CACHE exists, we exit the static files caching process. Hence, the 2 files added above will not get cached. Lastly, because the sw.js is made as it is, if a static file is not cached, its request will return 404. As a result, the icons are displayed on a shift refresh only.

@surma I know you had long conversations with @jeffposnick about how to write the sw few months ago so I wanted to ask your opinion on this before trying to fix it.

I was thinking of one of this way:

  1. Create a static file specific var VERSION and update the static cache based on it.
  2. Check cache existence of each static file independently (instead of the cache name only) and cache files when not found.
  3. Change the fetch so we cache static files when they are not found in the cache, instead of sending a 404 response.
  4. Some other way?

I would personally go with 3 or 2.

surma commented 8 years ago

I’ll go with 2. Option 3 might convey that a thing is working even though it is actually not when going offline. I’ll just refresh the entire static cache and rely on HTTP caching headers to not redownload data the user already has.

PR incoming.