-
Notifications
You must be signed in to change notification settings - Fork 509
Service worker not updating without force update #70
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
Comments
@LinusBorg @addyosmani - Any suggestions? |
Your problem is the caching header of the server for the service worker file. You need to set up your web server so the caching headers are set to 0. Currently your settings are: Cache-Control:max-age=31536000.
|
I can reproduce the same issue, the browser simply loads the old version that the service worker installed first time and doesn't get updated. |
Serviceworker should be updated as follow the guide https://developers.google.com/web/fundamentals/instant-and-offline/service-worker/lifecycle#updates, if serviceworker has different content(bytes) and server-side certainly can deliver newer version of servicewoker to client-side. I recommend that first check out server side always could serve a newer version of service worker by requests in browser because of there are many reason to counteract updates assets like cache-control. and then track the process of installing server worker via |
I tried both nginx and apache configuration to unset caching headers. Didn't work as expected. Then finally decided to go with Vue Template because didn't want to get into caching issues on production. |
@pushkardeshmukh1992 Please follow below steps to debug the issue you are facing
Thanks. |
particularly works exluding service-worker.js from cache
in this case I still have to clear browser cache and updates are available after second page reload. |
@aleksandrmelnyk I will re-try with this particular nginx config. Thanks! |
Please refer to Caching best practices & max-age gotchas - JakeArchibald.com It might be helpful to get you more understand about that. @pushkardeshmukh1992 It seems that the issue isn't involve to this pwa template directly. how about that close the issue? |
I am with the same problem, in mobile I do not have a clear cache button in browser, someone knows how to correct? |
I think it's a bad idea to cache index.html. js and css files have a different hash name every time you build them with some changes. If you don't cache index.html, you will fetch a fresh version of it every time and that fresh version will include new js and css files with new names. |
I used jakearchibald tips, for max-age: 0 to service-worker.js and works perfectly, when I update my code, the final user only needs to refresh the page, service-worker.js will do the job to cache all updates. |
Default behavior of sw-precache is to load resources from cache, them update the cache in the background. Next time you refresh the page, the browser will load the updated resources from cache. This Stackoverflow answer explains how to have better UX for the update: |
It works fine for me, when I disabled index.html from cache |
This is what worked for me - out sample project is here: https://github.com/dukecon/dukecon_pwa To the template we added two things:
Ad 1: we're using Apache httpd with a .htaccess file with the following contents: Ad 2: if a new version is available, this leads to a reload of the page some seconds after the user loaded the page. This works for us, but might not work for everyone else. Side note: we changed the setting of "staticFileGlobs" in webpack.prod.conf.js to ['dist/**/*.{js,html,css,png,gif,svg,ico}'] - the original version didn't include images and icons. Suggestion:
Please comment - I'm happy to create a PR for this. |
I've run into the same issue but i'm on a template version from september, A summary of optimal production cache-settings should really be included in the README.md - the serviceworker is basically just a giant pitfall as it is right now. Is there any way to quickly just disable this caching-feature for production? |
@telamon You can control cache in server-side, this is what I did and worked, I set max-age=0 for service-worker.js file. |
@rof20004 Yeah I know I'll attach my nginx-configuration at the end of this post, but what I mean is that it sucks finding out about the worker-loader design of this template through github issues, this information should be made available on the front-page, as it is now we've gone live in production for 2 months and I have no clue how many customers got infected with an outdated service-worker or how to purge their cache-stores short of changing domain. So yeah a heads-up that tells people to take extra care with the cache-settings in production would have been really appreciated back then. I will even go as far as stating that this issue is unresolved until a "PWA in production environment" chapter is available in the Here's my nginx tweak to achieve the same results:
|
Here is one for apache2:
|
@telamon I aggree with completly. |
add section why cache limitation is necessary with examples #70
If running express you can create a
Just a heads up, if piping through cloudflare you need to toggle on respect existing headers under caching. |
@aleksandrmelnyk Hi, I have this in my .htaccess(vue-router history mode for apache):
How can I integrate this code that you shared inside the same .htaccess, I tried this but not worked.
|
@rof20004 did you tried this in .htaccess
|
@dvikas Yes, I changed to this and worked:
I need to enable mod_headers in apache only, restart and enjoy :) |
I've done all of the above, this is my nginx config
This solves things half way for me Sometimes when i build my websites, different machine provide a white screen and the manifest.js / app.js results in a 404 which of course it doesn't exist anymore because now there is a new one, anyway only when i refresh the page i get the latest build, other times it builds and refreshes when i access and installs the update successfully . If i witness the previous build in the browser, and wait for my pipeline to finish its ok, successful, when i get home to check on my laptop that is two builds behind i get a white screen, i've tried everything so far. Any ideas? |
service-worker only works in https mode. |
Any solution for cloudflare? |
@mejiamanuel57 in fact, you only need to remove the cache from service-worker.js file. Maybe this can help you: |
Hi, Thank you @rof20004 I follow this tutorial: Creating a page rule for the service workers works. |
Hi, why do you disable etag ? |
Hi,
I installed Vue PWA template and tested on Apache localhost with offline feature (Dev tool). It works as expected.
I deployed same code to the production environment on Heroku. where it is not working as expected.
Even when I reload the page old service worker is still running and cached version of app which I get in offline mode is stale.
When I force update the service worker (From dev tool) then newer version of service worker is installed and only then it fetches fresh copy of project.
Here's my production webpack config.
I have not changed service worker code in index.html
Is there anything I am missing?
The text was updated successfully, but these errors were encountered: