Skip to content

Commit

Permalink
Merge pull request #1029 from Subhajit-2023-44/branch-5
Browse files Browse the repository at this point in the history
Add/Enable PWA (Progressive Web App) done ! #1010
  • Loading branch information
ankit071105 authored Nov 7, 2024
2 parents 8361a23 + 16141e1 commit 343e2ca
Show file tree
Hide file tree
Showing 6 changed files with 79 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.
4 changes: 4 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<link rel="stylesheet" href="index.css">
<link rel="stylesheet" href="why-us.css">
<link rel="stylesheet" href="navbar.css">
<link rel="manifest" href="/manifest.json">
<!-- this is for twitter icons -->
<script src="https://kit.fontawesome.com/3d20c433e1.js" crossorigin="anonymous"></script>

Expand Down Expand Up @@ -1695,6 +1696,9 @@ <h4>FIND US</h4>
</html>

<script src="chatbot.js"></script>

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

</body>

</html>
Expand Down
20 changes: 20 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "Ticket-Booking",
"short_name": "Ticket-Booking",
"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"
}
]
}
12 changes: 12 additions & 0 deletions scripts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// 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);
});
});
}
43 changes: 43 additions & 0 deletions sw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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 343e2ca

Please sign in to comment.