Comments (6)
I converted the service worker code from this template over to basically use what create-react-app uses where the service worker registration code is compiled with webpack (it's not in this template).
CRA progressive web app information
- Delete
build/service-worker-prod.js
andbuild/service-worker-dev.js
and related loading code fromindex.html
and frombuild/webpack.dev.js
andbuild/webpack.prod.js
- Port over
src/registerServiceWorker.js
from CRA - Add proper import from
src/index.js
Then you can import your Vuex store into src/registerServiceWorker.js
and dispatch a notification like this:
const notifyUserAboutUpdate = worker =>
store.dispatch(NEW_NOTIFICATION, {
text: 'App update available!',
secondary: true,
showReloadButton: true,
timeout: 0,
onClick: () => worker.postMessage({action: 'skipWaiting'})
})
function registerValidSW (swUrl) {
navigator.serviceWorker
.register(swUrl)
.then(registration => {
if (registration.waiting) {
console.log('New content has been available from last session; please refresh.')
notifyUserAboutUpdate(registration.waiting)
return
}
registration.onupdatefound = () => {
const installingWorker = registration.installing
installingWorker.onstatechange = () => {
if (installingWorker.state === 'installed') {
if (navigator.serviceWorker.controller) {
// At this point, the fresh content will have been added to the cache.
// It's the perfect time to display a "New content is
// available; please refresh." message in your web app.
console.log('New content is available; please refresh.')
notifyUserAboutUpdate(installingWorker)
} else {
// At this point, everything has been precached.
// It's the perfect time to display a
// "Content is cached for offline use." message.
console.log('Content is cached for offline use.')
}
}
}
}
})
.catch(error => {
console.error('Error during service worker registration:', error)
})
}
from pwa.
Me too, in fact, I did this and worked on desktop, but not in mobile.
from pwa.
There is a simpler way to access your Vue app from the outside. In your main.js prepend before new Vue()
:
window.App = new Vue({ ... })
Then your App instance is available in the global scope, you can access App.$data
, App.$store
and so on.
from pwa.
Many thanks @flybayer
from pwa.
There is a simpler way to access your Vue app from the outside. In your main.js prepend before
new Vue()
:window.App = new Vue({ ... })
Then your App instance is available in the global scope, you can access
App.$data
,App.$store
and so on.
It can be much cleaner to use EventBus
from pwa.
There is a simpler way to access your Vue app from the outside. In your main.js prepend before
new Vue()
:window.App = new Vue({ ... })
Then your App instance is available in the global scope, you can access
App.$data
,App.$store
and so on.It can be much cleaner to use EventBus
how to do that, please
from pwa.
Related Issues (20)
- Suggestion: serviceWorker.register path and routes issue HOT 2
- Offline support when using html5 history api HOT 1
- HELP: VueX and no-param-reassign HOT 3
- Active in Development? HOT 2
- SPA app using angular not working offline for pages other than Index
- Problem when importing firebase-messaging-sw to SW service worker. HOT 2
- Tapable is deprecated in Webpack 4 HOT 4
- offline caching options for pwa HOT 1
- Step missing in installation?
- Cloudflare's Under Attack Mode breaks Service Worker
- how i dynamically change my manifest.json file HOT 1
- How to disable "Add to Homescreen". HOT 1
- Failed to register a ServiceWorker
- Uncaught TypeError: Cannot read property 'call' of undefined
- PWA themeColor is not picking value from manifest.json file HOT 2
- Service Worker Error TypeError: Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script.
- Failed to register a ServiceWorker when app run on network address
- POST API not calling on mobile [Chrome v72.0.*] HOT 1
- Uncaught (in promise) DOMException
- Service Worker is not working as expected in react typescript
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pwa.