Skip to content

Commit

Permalink
Merge pull request #1199 from Subhajit-2023-44/1
Browse files Browse the repository at this point in the history
Add/Enable PWA (Progressive Web App) done ! #1189 🌟🌟🌟
  • Loading branch information
vimistify authored Nov 8, 2024
2 parents cdbdce1 + 36e6802 commit d869fc8
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 0 deletions.
Binary file added icon-192x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icon-512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" />
<link rel="stylesheet" href="responsive.css">

<link rel="manifest" href="/manifest.json">


<style>


Expand Down Expand Up @@ -1005,6 +1008,10 @@ <h3 style="font-size: 1.5rem; margin-bottom: 10px; color: darkorange;">
animateCircles();
});
</script>

<script src="script.js"></script> <!-- Link to your service worker registration script -->


</body>

</html>
24 changes: 24 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{

"name": "Bobble-AI",
"short_name": "Bobble-AI",
"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"
}
]

}


15 changes: 15 additions & 0 deletions scripts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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);
});
});

}

47 changes: 47 additions & 0 deletions sw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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);
}
})
);
})
);
});

0 comments on commit d869fc8

Please sign in to comment.