0

I am using sw-precache and sw-toolbox to manage my service worker. Let's say I have a css file which I want to cache

staticFileGlobs: ['public/asset/build/css/m_index.min.css']

It get's added to the service worker on running gulp task as

var precacheConfig = [["public/asset/build/css/m_college.min.css","8d9b0e69820ba2fab83c45e2884bd61f"]

The hash with the file helps me in cache busting when service worker is registered. All works fine.

Now consider a situation where a certain PC or user or browser is unable to register service worker and the file is served through the network to him every time. In this case, the file will get stored in the browser memory because there is no cache busting by default. And it might feed the old file to that user for a lifetime even after the developer has updated the file.

What is the way to handle this scenario?

1
  • Do you have some very spesific reason not to use individual file names for different versions (m_index.ajflhyow3uhkahfa.min.css for instance) of the files? That would solve the problem for all visitors. Commented Sep 6, 2017 at 4:44

2 Answers 2

1

I would use the Etag response header (https://developer.mozilla.org/en/docs/Web/HTTP/Headers/ETag) to avoid loading obsolete assets for users.

Sign up to request clarification or add additional context in comments.

Comments

0

For anyone looking out for answers, there is a simple solution - COOKIES.

While trying to register cookie if something fails set a cookie. This cookie than can be read on the backend before sending files If the cookie is not set, load files without cache busting else append a cache buster on the end to prevent browser caching where service worker is not running.

Because cookies are the only thing accessible directly on both frontend and backend.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.