Problem with service workers and stale code #645
Comments
|
All browsers listed below (Mac OS) run the app in off-line mode as expected. In my local environment, content updates with a new Restarting the browser shows updated content in all browsers. I'm on Mac OS 10.11.5 I don't know if there is a real solution, or if a solution is needed. But, in case restarting the browser is not desirable, in Chrome you can clear the cached content by:
A browser restart, or this procedure, needs to be done every time you run a production build in your browser, and is a local workaround only. How much of a problem this is depends on how frequently you update your app, and how critical having the latest content is to your end users. |
ncrawlins
commented
Jul 5, 2016
|
It's not a problem in development, because service workers aren't running. It's only a problem when a new version is deployed to production. It is being served from IIS 8.5 running .net core. Restarting chrome in windows does not fix it, I have to clear all cache or unregister the service workers using chrome://serviceworker-internals/ I have no problems clearing my cache, but right now we are getting active feedback from users that can't be expected to mess with browser settings, as basic as that may seem. They are getting a new version about once a week, sometimes more. I was hoping there was some way to maybe put a setting in the OfflinePlugin config or somewhere. So that when i pushed a new build it would know to grab the new index.html. But if that's just the way it's meant to work, then I guess I can just disable the offline stuff for now because they don't really need it, and the app is changing a lot. |
|
@mxstbr , anyone else, is there a production-ready solution to updating content in offline-first? |
mxstbr
added the
bug
label
Jul 7, 2016
|
Oh my, that sounds horrible @ncrawlins! @NekR, any input here? |
|
Okay, first of all, it's not that bad :-) Let me example you how Browser fetches
I guess
This is how it works. Of course, there is a way to update SW/AppCache when you want, you are developer after all :-) // offline-plugin config
// tell to it to generate events for SW
new OfflinePlugin({
ServiceWorker: {
events: true
}
})// client-side code
const runtime = require('offline-plugin/runtime');
runtime.install({
onUpdating: () => {
console.log('SW Event:', 'onUpdating');
},
onUpdateReady: () => {
console.log('SW Event:', 'onUpdateReady');
// Tells to new SW to take control immediately
runtime.applyUpdate();
},
onUpdated: () => {
console.log('SW Event:', 'onUpdated');
// Reload the webpage to reload into new version
window.location.reload();
},
onUpdateFailed: () => {
console.log('SW Event:', 'onUpdateFailed');
}
});There are similar option for AppCache:
@ncrawlins are use sure about that, can you re-check one more time? Here is how to test:
Thanks. |
|
Oh, and:
If you don't need it--then simply don't use it. But I should warn you that you cannot simply remove |
jakearchibald
commented
Jul 7, 2016
|
Here's a quick video where I run through the update cycle of a SW. https://twitter.com/jaffathecake/status/709011058938269696 - it's basically the same as Chrome's update model. |
|
Woah thanks for that @NekR and @jakearchibald – we should add that great explanation to the docs! |
|
@mxstbr Yeah, I think about it too. I'll it to |
ncrawlins
commented
Jul 8, 2016
•
I must have been misremembering. I can't reproduce that. Seems to be working as you described. |
|
So, is this still a bug then? @ncrawlins have you managed to make @mxstbr maybe we should include SW events by default into boilerplate? |
ncrawlins
commented
Jul 8, 2016
|
yep, it is working for me. sorry for the initial misinformation about the behavior, but the explanation of how it all works was very helpful. |
ncrawlins
closed this
Jul 8, 2016
|
No problem, I am glad to help. If something, here I wrote a doc based explanation here (same content, just reworded a bit): https://github.com/NekR/offline-plugin/blob/master/docs/updates.md |
ajarbol
commented
Nov 29, 2016
•
|
For the record I would like to mention that my default Nginx setup had
The defaults might be different in an Express or Apache setup, but maybe this could be considered an addition to https://github.com/mxstbr/react-boilerplate/blob/master/app/.nginx.conf @mxstbr |
|
Yeah, SW file should be served without cache enabled for it. Otherwise you may get stale SW up to 24h. Though, that's gonna change per spec SW file will always (unless opt-in) without taking cache into account. But that's future :-) |
gihrig
added a commit
to gihrig/react-boilerplate
that referenced
this issue
Dec 24, 2016
|
|
gihrig |
9d043c7
|
gihrig
added a commit
to gihrig/react-boilerplate
that referenced
this issue
Dec 24, 2016
|
|
gihrig |
2838fae
|
gihrig
referenced
this issue
Dec 24, 2016
Merged
docs(servers): update server conf files for offline-first per #645 #1381
|
I opened PR #1381 to address server cache settings. If others could take a look that would be helpful. |
mxstbr
added a commit
that referenced
this issue
Jan 14, 2017
|
|
gihrig + mxstbr |
c75682f
|
AnhHT
added a commit
to AnhHT/react-boilerplate
that referenced
this issue
Jan 18, 2017
|
|
AnhHT |
034ab9d
|
AnhHT
added a commit
to AnhHT/react-boilerplate
that referenced
this issue
Jan 20, 2017
|
|
AnhHT |
e514973
|
ncrawlins commentedJul 5, 2016
Sorry if there is something fundamental I'm missing in the docs, but I can't figure this out. When I build for production and push to the server, the service workers (or app cache maybe?) still serve old versions of the app when I navigate to the production site. If hit CTRL-F5 in Chrome to force refresh, I see the new version of the app, but if I then just hit F5, it will revert to the old version (served by the service workers, I guess?)
Is there something I need to be doing when pushing a new version of the app to production to let the service workers know they need to update their cache?