-
Notifications
You must be signed in to change notification settings - Fork 167
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
Cache issue #403
Comments
New-ish to React, but this has worked forever in Angular world (it's a natural process in the cli there, but can be handled in webpack): This way the filename changes with each build, invalidating cached copies. https://stackoverflow.com/questions/39238163/how-can-i-make-webpack-use-a-cache-busting-suffix |
Thank you for your answer, but my built files already have a chunkhash (i.e. So, to temporarily resolve the problem, I edited new SWPrecacheWebpackPlugin({
cacheId: 'website',
filename: 'service-worker.js',
maximumFileSizeToCacheInBytes: 8388608,
// Ensure all our static, local assets are cached.
staticFileGlobs: [path.dirname(assetsPath) + '/**/*.{js,css,png,jpg,gif,svg,eot,ttf,woff,woff2}'],
stripPrefix: path.dirname(assetsPath),
directoryIndex: '/',
verbose: true,
navigateFallback: '/dist/index.html',
runtimeCaching: [{
urlPattern: /\/api\/widget\/load(.*)/,
handler: 'networkFirst',
options: {
debug: true
}
}]
}) For me, it is an issue with the service worker, so I have also created another issue: goldhand/sw-precache-webpack-plugin#147 |
I tested with 6a6cdc8, but that doesn't completely fix the problem. I must refresh the page two times to obtain the last version of the website. However, I added this code: await navigator.serviceWorker.register('/dist/service-worker.js', { scope: '/' }).then(reg => {
reg.onupdatefound = () => {
const installingWorker = reg.installing;
installingWorker.onstatechange = () => {
switch (installingWorker.state) {
case 'installed':
if (navigator.serviceWorker.controller) {
console.log('New update available');
} else {
console.log('No update available');
}
break;
default:
break;
}
};
};
}); And when I have:
I need to refresh the page a first time to obtain |
Should the browser be refreshed as soon as the service worker is updated? or offer it to the user? |
To be honest, I don't know what is the best solution. However, we can take Inbox by Gmail as an example. If a user is staying inside the application a long time and an update of the service worker is done during this period, a "toast" appears and notifies the user that a new update is available. Otherwise, when a user reloads the website, he has the last version. |
I added this commit (f02d1ce) and I would add a toast that propose to refresh the page. |
Hi,
Firstly, thanks @bertho-zero for this repo!
So, I have an issue when I add a new page to my router.
When a person tries to visit the new page, he is redirected to the 404 page because he doesn't have the new version of the site in his cached files.
However, for someone who visits the website for the first time, there is no problem and he can see the new page.
How can I fix this issue?
Thank you,
Romain
The text was updated successfully, but these errors were encountered: