-
Notifications
You must be signed in to change notification settings - Fork 506
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
Service Worker not busting cache. #177
Comments
I too can confirm this.
I also use offline-plugin for webpack in another app that uses a similar set up with no issues. Perhaps we can take a look at what they are doing different? Currently my app will not update but uses cached files instead unless I hard clear the browser with dev tools open. This occurs in live production, harder to reproduce or tell in dev since its hot reloaded. |
Are you serving your |
I get same in Dev mode also, would be good if it could work like productio does, can we not just check for localhost else activate worker? |
I also disabled cache in nginx, any thoughts? |
Any updates? Cannot update the page hosted on Github Pages. |
This works for me, within registerServiceWorker.js in the updated() function add:
Full result
|
this is a huge pain, how does one update the content or at least ask the user to update content? |
@xerosanyam here is a crude way: |
the problem is reloading doesn't work too. the problem is with cache burst |
Are you using a service worker and manifest file correctly? Make sure your manifest file doesn't get cache. Once it changes the service worker will update all the new files in the background and then you can again reload once the |
I used vue-cli and chose pwa support. I thought it'll all be managed. |
No only the bundling of the service-worker and manifest file is managed. Cache busting isn't hence this issue. Here is my setup that works: Update these two files as follows
And in your regis
Now every time you make build make sure to update the version within the |
Sorry one more file. In you Update the options or add it if it is't used already the following:
|
Thank you so much! |
My service-worker file looks like this.
It says that I shouldn't change this file directly, so for updating version, is there any better way ? |
That is because it currently gets generated on every build. You need to update the
This tells the pwa plugin that you supply your own service-worker. |
I've create a test project on production to solve same problem. So now it's work!
Add refresh link to
and simplest
I'm not sure, but it seems I already try something like that a few months ago and it did not work. It works now, which means problem probably was gone with a new package version (I tested |
This is a great solution and it works properly. I've found an alternative without the need of a human interaction: /* tslint:disable:no-console */
import { register } from 'register-service-worker';
if (process.env.NODE_ENV === 'production') {
register(`${process.env.BASE_URL}service-worker.js`, {
ready() {
console.log(
'App is being served from cache by a service worker.\n' +
'For more details, visit https://goo.gl/AFskqB',
);
},
registered() {
console.log('Service worker has been registered.');
},
cached() {
console.log('Content has been cached for offline use.');
},
updatefound() {
console.log('New content is downloading.');
},
updated() {
console.log('New content is available; please refresh.');
const script = document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.innerHTML = 'window.location.reload(true);';
const meta = document.createElement('meta');
meta.setAttribute('http-equiv', 'refresh');
meta.setAttribute('content', '0;');
const noscript = document.createElement('noscript');
noscript.appendChild(meta);
const body = document.getElementsByTagName('body')[0];
body.appendChild(script);
body.appendChild(noscript);
},
offline() {
console.log('No internet connection found. App is running in offline mode.');
},
error(error) {
console.error('Error during service worker registration:', error);
},
});
} I hope help you :) |
This works for me. registerServiceWorker.js
vue.config.js
Let me know if it works for you. Or if you have any comments or concerns! |
Just thought I might throw in my two cents for tying it to the package.json version service-worker.js // Do not touch this line
const LATEST_VERSION = '3.1.0'; bust-cache.js const fs = require('fs');
const { version } = require('./package.json');
let swFile = fs.readFileSync('./service-worker.js', 'utf-8');
swFile = swFile.replace(/LATEST_VERSION = '[^']+';/, `LATEST_VERSION = '${version}';`);
fs.writeFileSync('./service-worker.js', swFile); package.json "scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"version": "node bust-cache.js && git add package.json service-worker.js"
}, Then just run |
Hello, I've got a weird issue.
In devtools, I have cache disabled.
When I hit
ctrl+r
, it still lads a cached old file with an error.When I hit
shift+ctrl+r
, no problem, and the new file is used and error is gone.Despite Chrome devtools having cache disabled, that has no effect. Only pressing
shift+ctrl+r
loads the non-cached version, while pressingctrl+r
always loads the older cached file.Seems like this has to do with service worker. How do I ensure that caching works properly with the service worker, to eliminate that as possible source of the problem?
Note, I've loaded the production build with a static server a couple times to test it, not sure if that's somehow messing up with the service worker while I'm in
dev
mode.I'm experiencing this in
dev
mode.The text was updated successfully, but these errors were encountered: