debugging PWA
This commit is contained in:
parent
fac2662460
commit
569ce42487
3 changed files with 26 additions and 42 deletions
|
@ -189,15 +189,13 @@
|
|||
|
||||
// Hide the installation button once the app is installed
|
||||
document.getElementById('installButton').style.display = 'none';
|
||||
|
||||
// Hide the installation instructions once the app is installed
|
||||
document.getElementById('install-instructions').style.display = 'none';
|
||||
}
|
||||
|
||||
// Show installation instructions only if app is not already installed
|
||||
if (!window.matchMedia('(display-mode: standalone)').matches) {
|
||||
window.addEventListener('beforeinstallprompt', (event) => {
|
||||
event.preventDefault();
|
||||
document.getElementById('install-instructions').style.display = 'block';
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,11 +1,17 @@
|
|||
{
|
||||
"name": "EUR-DZD",
|
||||
"short_name": "EUR DZD",
|
||||
"name": "EUR-DZD Calculator",
|
||||
"short_name": "EUR-DZD",
|
||||
"description": "Convert Euro to Algerian Dinar and vice versa.",
|
||||
"icons": [
|
||||
{
|
||||
"src": "icon.png",
|
||||
"sizes": "192x192",
|
||||
"type": "image/png"
|
||||
},
|
||||
{
|
||||
"src": "icon.png",
|
||||
"sizes": "512x512",
|
||||
"type": "image/png"
|
||||
}
|
||||
],
|
||||
"start_url": "/index.html",
|
||||
|
@ -14,4 +20,3 @@
|
|||
"theme_color": "#4CAF50"
|
||||
}
|
||||
|
||||
|
|
@ -1,48 +1,29 @@
|
|||
const CACHE_NAME = 'eur-dzd-calculator-v1';
|
||||
const urlsToCache = [
|
||||
'/',
|
||||
'/index.html',
|
||||
'/icon.png',
|
||||
'/manifest.json',
|
||||
// Add more URLs of assets to cache here
|
||||
];
|
||||
|
||||
self.addEventListener('install', function(event) {
|
||||
self.addEventListener('install', event => {
|
||||
event.waitUntil(
|
||||
caches.open(CACHE_NAME)
|
||||
.then(function(cache) {
|
||||
return cache.addAll([
|
||||
'/index.html',
|
||||
'/manifest.json',
|
||||
'/icon.png',
|
||||
'/style.css',
|
||||
'/script.js',
|
||||
]);
|
||||
})
|
||||
.then(cache => cache.addAll(urlsToCache))
|
||||
.catch(error => console.error('Error caching assets:', error))
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', function(event) {
|
||||
self.addEventListener('fetch', event => {
|
||||
event.respondWith(
|
||||
caches.match(event.request)
|
||||
.then(function(response) {
|
||||
.then(response => {
|
||||
if (response) {
|
||||
return response;
|
||||
return response; // Serve cached asset if available
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
return fetch(event.request); // Otherwise, fetch from network
|
||||
})
|
||||
.catch(error => console.error('Error fetching asset:', error))
|
||||
);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue