Skip to content
Open

Pwa #93

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,30 @@
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+Cherokee&family=Noto+Sans:ital,wght@0,400;0,700;1,400&display=swap" rel="stylesheet">
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<!-- <noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<div id="modal-root"></div>
<!--

This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.

To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
To create a production bundle, use `npm run build` or `yarn build`. -->
<div id="root"></div>
<div id="modal-root"></div>
<script>
if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.register('%PUBLIC_URL%/serviceWorker.js').then(function(registration){
console.log('ServiceWorker registered: ', registration.scope);
}, function(err) {
console.log('ServiceWorker unable to be registered: ', err);
});
});
}
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"sizes": "512x512"
}
],
"start_url": ".",
"start_url": "index.html",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
Expand Down
22 changes: 22 additions & 0 deletions public/serviceWorker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
let CACHE_NAME = 'my-site-cache-v1';
const urlsToCache=[
'/',
'/index.html',
];
self.addEventListener('install', function(event) {
event.waitUntil(
caches.open(CACHE_NAME).then(function(cache){
console.log('Opened cache');
return cache.addAll(urlsToCache);
})
);
self.skipWaiting();
});
self.addEventListener('fetch', function(event){
event.respondWith(caches.match(event.request).then(function(response){
if (response) {
return response;
}
return fetch(event.request);
}));
})