diff --git a/icon-192x192.png b/icon-192x192.png new file mode 100644 index 0000000..8d41e9c Binary files /dev/null and b/icon-192x192.png differ diff --git a/icon-512x512.png b/icon-512x512.png new file mode 100644 index 0000000..e8ad636 Binary files /dev/null and b/icon-512x512.png differ diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..88ee5e8 --- /dev/null +++ b/manifest.json @@ -0,0 +1,21 @@ +{ + "name": "NexTrade", + "short_name": "NexTrade", + "start_url": "/", + "display": "standalone", + "background_color": "#ffffff", + "theme_color": "#000000", + "icons": [ + { + "src": "/icon-192x192.png", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "/icon-512x512.png", + "sizes": "512x512", + "type": "image/png" + } + ] + } + \ No newline at end of file diff --git a/scripts.js b/scripts.js new file mode 100644 index 0000000..c201510 --- /dev/null +++ b/scripts.js @@ -0,0 +1,14 @@ +// Register the service worker +if ('serviceWorker' in navigator) { + window.addEventListener('load', () => { + navigator.serviceWorker.register('/sw.js') // Pointing to the sw.js file + .then(registration => { + console.log('ServiceWorker registration successful:', registration); + }) + .catch(error => { + console.error('ServiceWorker registration failed:', error); + }); + }); + + +} diff --git a/sw.js b/sw.js new file mode 100644 index 0000000..4544622 --- /dev/null +++ b/sw.js @@ -0,0 +1,46 @@ +const CACHE_NAME = 'my-pwa-cache-v1'; +const urlsToCache = [ + '/', + '/index.html', + '/styles.css', + '/scripts.js', + '/manifest.json', + '/icon-192x192.png', + '/icon-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); + } + }) + ); + }) + ); +}); \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index d8d06cc..3b0a73e 100644 --- a/templates/index.html +++ b/templates/index.html @@ -7,6 +7,7 @@ +
+ +