gridsome-plugin-pwa icon indicating copy to clipboard operation
gridsome-plugin-pwa copied to clipboard

General-question: Service-Worker results to old CSS when updating.

Open pmochine opened this issue 4 years ago • 6 comments

Sorry, I don't know really where to ask this question except for here.

When I upload a new build to my server, and I visit for example https://example.com/imprint, the result is that the CSS is missing, since the CSS file got a newly generated hash name but the service-worker returns the old HTML build with the old CSS hash name.

The only solution is to refresh with "shift+cmd+4", to delete all cache and to restart the service worker. Obviously, this is not what normal users would do.

How can I fix this? Any idea? 🙈

Here is a short gif for you to see the problem in action

philippmoch2

At the very last second, I'm hard-refreshing the page and only then I see the correct imprint page.

pmochine avatar Jun 08 '20 12:06 pmochine

You may want to update to latest version of the plugin. Issue is resolved and my site https://rishabhchawla.now.sh/ uses latest and don't face such issues anymore.

rishabh3112 avatar Jun 09 '20 05:06 rishabh3112

@rishabh3112 weird! I still struggle with this issue. Even though I have the latest version of the plugin (0.0.17). At first, I thought it might be an issue with Nginx, caching the HTML file, but no it's set to no-cache for HTML files.

pmochine avatar Jun 10 '20 15:06 pmochine

Ok I resolved the bug. Under Application go to "Clear storaage" and clear the whole site. Only then it works!

pmochine avatar Jun 19 '20 17:06 pmochine

Update: Unfortunately, the problem is back and I'm not even sure what's wrong :(

pmochine avatar Jun 21 '20 09:06 pmochine

@pmochine if you server allows you to do so you should try disabling cache for your service-workers.js files. I believe that should fix your issues. The following can be used:

If using nginx

location = /service-worker.js {
    expires off;
    add_header Cache-Control: no-store;
    access_log off;
}

If using apache (I haven't personally tested) but obtained from gridsome-plugin-service-worker docs

<Files /service-worker.js>
  FileETag None
  <ifModule mod_headers.c>
     Header unset ETag
     Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
     Header set Pragma "no-cache"
     Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
  </ifModule>
</Files>

<Files /assets/js/service-worker.js>
  FileETag None
  <ifModule mod_headers.c>
     Header unset ETag
     Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
     Header set Pragma "no-cache"
     Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
  </ifModule>
</Files>

dikaio avatar Jul 13 '20 02:07 dikaio

@dikaio Thank you for your time and your comment. I appreciate it.

Here is my nginx setting. But this should be fine as well right?

#Disable cache in service-worker
location = /service-worker.js {
    add_header Cache-Control "public, max-age=0, must-revalidate";
}

pmochine avatar Jul 13 '20 20:07 pmochine