SW
This commit is contained in:
parent
a9aa558d54
commit
0984eb2a83
8 changed files with 132 additions and 59 deletions
BIN
icon-192x192.png
Normal file
BIN
icon-192x192.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
BIN
icon-256x256.png
Normal file
BIN
icon-256x256.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 33 KiB |
BIN
icon-384x384.png
Normal file
BIN
icon-384x384.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 62 KiB |
BIN
icon-512x512.png
Normal file
BIN
icon-512x512.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 97 KiB |
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
<link rel="stylesheet" href="css/styles.css?v=1.0">
|
<link rel="stylesheet" href="css/styles.css?v=1.0">
|
||||||
<meta name="theme-color" content="#4285f4" />
|
<meta name="theme-color" content="#4285f4" />
|
||||||
<link rel="manifest" href="/manifest.json">
|
<link rel="manifest" href="/manifest.webmanifest">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|
|
@ -1,58 +0,0 @@
|
||||||
{
|
|
||||||
"short_name": "Weather",
|
|
||||||
"name": "Weather: Do I need an umbrella?",
|
|
||||||
"icons": [
|
|
||||||
{
|
|
||||||
"src": "/images/icons-vector.svg",
|
|
||||||
"type": "image/svg+xml",
|
|
||||||
"sizes": "512x512"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"src": "/images/icons-192.png",
|
|
||||||
"type": "image/png",
|
|
||||||
"sizes": "192x192"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"src": "/images/icons-512.png",
|
|
||||||
"type": "image/png",
|
|
||||||
"sizes": "512x512"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"id": "/?source=pwa",
|
|
||||||
"start_url": "/?source=pwa",
|
|
||||||
"background_color": "#3367D6",
|
|
||||||
"display": "standalone",
|
|
||||||
"scope": "/",
|
|
||||||
"theme_color": "#3367D6",
|
|
||||||
"shortcuts": [
|
|
||||||
{
|
|
||||||
"name": "How's weather today?",
|
|
||||||
"short_name": "Today",
|
|
||||||
"description": "View weather information for today",
|
|
||||||
"url": "/today?source=pwa",
|
|
||||||
"icons": [{ "src": "/images/today.png", "sizes": "192x192" }]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "How's weather tomorrow?",
|
|
||||||
"short_name": "Tomorrow",
|
|
||||||
"description": "View weather information for tomorrow",
|
|
||||||
"url": "/tomorrow?source=pwa",
|
|
||||||
"icons": [{ "src": "/images/tomorrow.png", "sizes": "192x192" }]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "Weather forecast information",
|
|
||||||
"screenshots": [
|
|
||||||
{
|
|
||||||
"src": "/images/screenshot1.png",
|
|
||||||
"type": "image/png",
|
|
||||||
"sizes": "540x720",
|
|
||||||
"form_factor": "narrow"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"src": "/images/screenshot2.jpg",
|
|
||||||
"type": "image/jpg",
|
|
||||||
"sizes": "720x540",
|
|
||||||
"form_factor": "wide"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
49
manifest.webmanifest
Normal file
49
manifest.webmanifest
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
{
|
||||||
|
"short_name": "NeonXP",
|
||||||
|
"name": "NeonXP PWA",
|
||||||
|
"icons": [
|
||||||
|
{
|
||||||
|
"src": "/icon-192x192.png",
|
||||||
|
"sizes": "192x192",
|
||||||
|
"type": "image/png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "/icon-256x256.png",
|
||||||
|
"sizes": "256x256",
|
||||||
|
"type": "image/png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "/icon-384x384.png",
|
||||||
|
"sizes": "384x384",
|
||||||
|
"type": "image/png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "/icon-512x512.png",
|
||||||
|
"sizes": "512x512",
|
||||||
|
"type": "image/png"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"id": "/?source=pwa",
|
||||||
|
"start_url": "/?source=pwa",
|
||||||
|
"display": "standalone",
|
||||||
|
"scope": "/",
|
||||||
|
"theme_color": "#9013fe",
|
||||||
|
"background_color": "#4a90e2",
|
||||||
|
"shortcuts": [
|
||||||
|
{
|
||||||
|
"name": "How's weather today?",
|
||||||
|
"short_name": "Today",
|
||||||
|
"description": "View weather information for today",
|
||||||
|
"url": "/today?source=pwa",
|
||||||
|
"icons": [{ "src": "icon-192x192.png", "sizes": "192x192" }]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "How's weather tomorrow?",
|
||||||
|
"short_name": "Tomorrow",
|
||||||
|
"description": "View weather information for tomorrow",
|
||||||
|
"url": "/tomorrow?source=pwa",
|
||||||
|
"icons": [{ "src": "icon-192x192.png", "sizes": "192x192" }]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Sample pwa"
|
||||||
|
}
|
82
service-worker.js
Normal file
82
service-worker.js
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
/*
|
||||||
|
Copyright 2015, 2019 Google Inc. All Rights Reserved.
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Incrementing OFFLINE_VERSION will kick off the install event and force
|
||||||
|
// previously cached resources to be updated from the network.
|
||||||
|
const OFFLINE_VERSION = 1;
|
||||||
|
const CACHE_NAME = 'offline';
|
||||||
|
|
||||||
|
const STATIC_URLS = [
|
||||||
|
"/",
|
||||||
|
"/index.html",
|
||||||
|
"/manifest.webmanifest",
|
||||||
|
"/icon-192x192.png",
|
||||||
|
"/icon-256x256.png",
|
||||||
|
"/icon-384x384.png",
|
||||||
|
"/icon-512x512.png"
|
||||||
|
];
|
||||||
|
|
||||||
|
self.addEventListener('install', (event) => {
|
||||||
|
event.waitUntil((async () => {
|
||||||
|
const cache = await caches.open(CACHE_NAME);
|
||||||
|
await cache.addAll(STATIC_URLS);
|
||||||
|
})());
|
||||||
|
});
|
||||||
|
|
||||||
|
self.addEventListener('activate', (event) => {
|
||||||
|
event.waitUntil((async () => {
|
||||||
|
// Enable navigation preload if it's supported.
|
||||||
|
// See https://developers.google.com/web/updates/2017/02/navigation-preload
|
||||||
|
if ('navigationPreload' in self.registration) {
|
||||||
|
await self.registration.navigationPreload.enable();
|
||||||
|
}
|
||||||
|
})());
|
||||||
|
|
||||||
|
// Tell the active service worker to take control of the page immediately.
|
||||||
|
self.clients.claim();
|
||||||
|
});
|
||||||
|
|
||||||
|
self.addEventListener('fetch', (event) => {
|
||||||
|
// We only want to call event.respondWith() if this is a navigation request
|
||||||
|
// for an HTML page.
|
||||||
|
if (event.request.mode === 'navigate') {
|
||||||
|
event.respondWith((async () => {
|
||||||
|
try {
|
||||||
|
// First, try to use the navigation preload response if it's supported.
|
||||||
|
const preloadResponse = await event.preloadResponse;
|
||||||
|
if (preloadResponse) {
|
||||||
|
return preloadResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
const networkResponse = await fetch(event.request);
|
||||||
|
return networkResponse;
|
||||||
|
} catch (error) {
|
||||||
|
// catch is only triggered if an exception is thrown, which is likely
|
||||||
|
// due to a network error.
|
||||||
|
// If fetch() returns a valid HTTP response with a response code in
|
||||||
|
// the 4xx or 5xx range, the catch() will NOT be called.
|
||||||
|
console.log('Fetch failed; returning offline page instead.', error);
|
||||||
|
|
||||||
|
const cache = await caches.open(CACHE_NAME);
|
||||||
|
const cachedResponse = await cache.match(OFFLINE_URL);
|
||||||
|
return cachedResponse;
|
||||||
|
}
|
||||||
|
})());
|
||||||
|
}
|
||||||
|
|
||||||
|
// If our if() condition is false, then this fetch handler won't intercept the
|
||||||
|
// request. If there are any other fetch handlers registered, they will get a
|
||||||
|
// chance to call event.respondWith(). If no fetch handlers call
|
||||||
|
// event.respondWith(), the request will be handled by the browser as if there
|
||||||
|
// were no service worker involvement.
|
||||||
|
});
|
Loading…
Reference in a new issue