diff --git a/images/logo-192x192.png b/images/logo-192x192.png new file mode 100644 index 00000000..29e63df4 Binary files /dev/null and b/images/logo-192x192.png differ diff --git a/images/logo-512x512.png b/images/logo-512x512.png new file mode 100644 index 00000000..fdc50d6d Binary files /dev/null and b/images/logo-512x512.png differ diff --git a/index.html b/index.html index 3ce22e06..f2ded584 100644 --- a/index.html +++ b/index.html @@ -26,6 +26,9 @@ + + + diff --git a/manifest.json b/manifest.json new file mode 100644 index 00000000..24b19535 --- /dev/null +++ b/manifest.json @@ -0,0 +1,21 @@ +{ + "name": "Collect your GamingTools", + "short_name": "Collect your GamingTools", + "description": "A responsive and dynamic website to showcase the best gaming accessories for every gamer!", + "start_url": "/index.html", + "display": "standalone", + "background_color": "#ffffff", + "theme_color": "#000000", + "icons": [ + { + "src": "/images/logo-192x192.png", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "/images/logo-512x512.png", + "sizes": "512x512", + "type": "image/png" + } + ] + } diff --git a/script.js b/script.js index 1787e9e1..3054beba 100644 --- a/script.js +++ b/script.js @@ -204,4 +204,17 @@ function testimonialJs() { }); } -testimonialJs(); \ No newline at end of file +testimonialJs(); + +// Service Worker code for PWA +if ('serviceWorker' in navigator) { + window.addEventListener('load', () => { + navigator.serviceWorker.register('/service-worker.js') + .then((registration) => { + console.log('ServiceWorker registration successful with scope: ', registration.scope); + }) + .catch((error) => { + console.log('ServiceWorker registration failed: ', error); + }); + }); +} diff --git a/service-worker.js b/service-worker.js new file mode 100644 index 00000000..c6e96613 --- /dev/null +++ b/service-worker.js @@ -0,0 +1,43 @@ +const CACHE_NAME = 'my-pwa-cache-v1'; +const urlsToCache = [ + '/', + '/index.html', + '/styles.css', + '/script.js', + '/manifest.json', + '/images/logo-192x192.png', + '/images/logo-512x512.png' +]; + +self.addEventListener('install', (event) => { + event.waitUntil( + caches.open(CACHE_NAME) + .then((cache) => { + return cache.addAll(urlsToCache); + }) + ); +}); + +self.addEventListener('fetch', (event) => { + event.respondWith( + caches.match(event.request) + .then((response) => { + return response || fetch(event.request); + }) + ); +}); + +self.addEventListener('activate', (event) => { + const cacheWhitelist = [CACHE_NAME]; + event.waitUntil( + caches.keys().then((cacheNames) => { + return Promise.all( + cacheNames.map((cacheName) => { + if (!cacheWhitelist.includes(cacheName)) { + return caches.delete(cacheName); + } + }) + ); + }) + ); +});