debugging PWA functionality

This commit is contained in:
Tobi 2024-04-09 09:53:54 +02:00
parent c2c34d96ec
commit e50ece4fbc
3 changed files with 25 additions and 3 deletions

View file

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>Exchange Rate Calculator</title>
<title>EUR DZD</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="manifest" href="/manifest.json">
<meta name="apple-mobile-web-app-capable" content="yes">

View file

@ -1,6 +1,6 @@
{
"name": "EUR-DZD Calculator",
"short_name": "Exchange Calculator",
"short_name": "EUR DZD",
"icons": [
{
"src": "icon.png",

View file

@ -8,6 +8,8 @@ self.addEventListener('install', function(event) {
'/index.html',
'/manifest.json',
'/icon.png',
'/style.css',
'/script.js',
]);
})
);
@ -20,7 +22,27 @@ self.addEventListener('fetch', function(event) {
if (response) {
return response;
}
return fetch(event.request);
let fetchRequest = event.request.clone();
return fetch(fetchRequest)
.then(function(response) {
if (!response || response.status !== 200 || response.type !== 'basic') {
return response;
}
let responseToCache = response.clone();
caches.open(CACHE_NAME)
.then(function(cache) {
cache.put(event.request, responseToCache);
});
return response;
})
.catch(function(error) {
console.error('Error fetching and caching:', error);
});
})
);
});