Skip to content

Commit

Permalink
Merge pull request #399 from Subhajit-2023-44/pwa
Browse files Browse the repository at this point in the history
Add PWA (Progressive Web App) done !
  • Loading branch information
Harshdev098 authored Nov 8, 2024
2 parents 97e2e53 + 4bfd8fc commit 2aae24b
Show file tree
Hide file tree
Showing 6 changed files with 87 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.
22 changes: 22 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "Research-Nexas",
"short_name": "Research-Nexas",
"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"
}
]

}

5 changes: 5 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
<link rel="stylesheet" type="text/css" href="css/faq_style.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css">
<link href='https://unpkg.com/[email protected]/css/boxicons.min.css' rel='stylesheet'>

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

<title>Research Nexas</title>
</head>

Expand Down Expand Up @@ -1097,6 +1100,8 @@ <h2>What feature of Research-Nexas do you find most valuable?</h2>

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

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

</body>

</html>
14 changes: 14 additions & 0 deletions public/script/scripts.js
Original file line number Diff line number Diff line change
@@ -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);
});
});


}
46 changes: 46 additions & 0 deletions sw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const CACHE_NAME = 'my-pwa-cache-v1';
const urlsToCache = [
'/',
'/index.html',
'/styles.css',
'/script/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 2aae24b

Please sign in to comment.