Declaritively initializing service worker
This commit is contained in:
parent
fd5a8786d0
commit
6bf094a4c1
@ -4,9 +4,12 @@ import ReactDOM from 'react-dom';
|
|||||||
import App from '../../components/App';
|
import App from '../../components/App';
|
||||||
|
|
||||||
import '../../style.css';
|
import '../../style.css';
|
||||||
import '../../service-worker';
|
import { setupServiceWorker } from '../../service-worker';
|
||||||
import { setupGA } from '../../analytics';
|
import { setupGA } from '../../analytics';
|
||||||
|
|
||||||
|
if (process.env.NODE_ENV === 'production') {
|
||||||
|
setupServiceWorker();
|
||||||
|
}
|
||||||
setupGA();
|
setupGA();
|
||||||
|
|
||||||
ReactDOM.render(<App/>, document.getElementById('root'));
|
ReactDOM.render(<App/>, document.getElementById('root'));
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
if ('serviceWorker' in navigator && process.env.NODE_ENV === 'production') {
|
const setupServiceWorker = () => {
|
||||||
window.addEventListener('load', () => {
|
if ('serviceWorker' in navigator) {
|
||||||
navigator.serviceWorker.register('/sw.js')
|
window.addEventListener('load', () => {
|
||||||
.then(registration => {
|
navigator.serviceWorker.register('/sw.js')
|
||||||
console.log('SW registered:', registration); // eslint-disable-line no-console
|
.then(registration => {
|
||||||
})
|
console.log('SW registered:', registration); // eslint-disable-line no-console
|
||||||
.catch(registrationError => {
|
})
|
||||||
console.log('SW registration failed:', registrationError); // eslint-disable-line no-console
|
.catch(registrationError => {
|
||||||
});
|
console.log('SW registration failed:', registrationError); // eslint-disable-line no-console
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export { setupServiceWorker };
|
||||||
|
Loading…
Reference in New Issue
Block a user