add service worker
This commit is contained in:
parent
a97d4fcb28
commit
d7e3fe8906
@ -89,7 +89,7 @@ function nouvelEssai() {
|
||||
})
|
||||
play(sonPerdu)
|
||||
if (confirm(`Perdu ! Le mot à trouver était : ${motATrouver.toUpperCase()}.\nRéessayer ?`)) nouvellePartie()
|
||||
|
||||
else nbEssais = 0
|
||||
}
|
||||
}
|
||||
|
||||
@ -175,4 +175,9 @@ function onsubmit(event) {
|
||||
} else {
|
||||
this.reportValidity()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.register('service-worker.js');
|
||||
}
|
86
service-worker.js
Normal file
86
service-worker.js
Normal file
@ -0,0 +1,86 @@
|
||||
/*
|
||||
Copyright 2015, 2019, 2020 Google LLC. 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";
|
||||
// Customize this with a different URL if needed.
|
||||
const OFFLINE_URL = "index.html";
|
||||
|
||||
self.addEventListener("install", (event) => {
|
||||
event.waitUntil(
|
||||
(async () => {
|
||||
const cache = await caches.open(CACHE_NAME);
|
||||
// Setting {cache: 'reload'} in the new request will ensure that the
|
||||
// response isn't fulfilled from the HTTP cache; i.e., it will be from
|
||||
// the network.
|
||||
await cache.add(new Request(OFFLINE_URL, { cache: "reload" }));
|
||||
})()
|
||||
);
|
||||
// Force the waiting service worker to become the active service worker.
|
||||
self.skipWaiting();
|
||||
});
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// Always try the network first.
|
||||
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.
|
||||
});
|
22
style.css
22
style.css
@ -1,14 +1,22 @@
|
||||
:root {
|
||||
font-size: 125%;
|
||||
nav ul {
|
||||
align-items: start;
|
||||
}
|
||||
|
||||
nav button svg {
|
||||
display: block;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 2.5em;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 2.1em;
|
||||
}
|
||||
|
||||
h1, h2 {
|
||||
text-align: center;
|
||||
filter: drop-shadow(0.08em 0.06em #8888);
|
||||
text-shadow: 0.08em 0.06em #8888;
|
||||
}
|
||||
|
||||
h1 img,
|
||||
@ -19,6 +27,7 @@ h2 img {
|
||||
padding: 0;
|
||||
height: 0.75em;
|
||||
vertical-align: baseline;
|
||||
filter: drop-shadow(0.08em 0.06em #8888);
|
||||
}
|
||||
|
||||
label.option {
|
||||
@ -33,10 +42,11 @@ label.option {
|
||||
}
|
||||
|
||||
input.lettre {
|
||||
font-size: 1.5em;
|
||||
font-size: 1.6em;
|
||||
font-weight: bold;
|
||||
text-transform: capitalize;
|
||||
width: 1.3em;
|
||||
height: 1.3em;
|
||||
width: 1.5em;
|
||||
height: 1.5em;
|
||||
padding: 0.15em;
|
||||
text-align: center;
|
||||
border-radius: 0.3rem;
|
||||
|
Loading…
x
Reference in New Issue
Block a user