feat: Add service worker for offline install

This commit is contained in:
2026-05-31 00:43:24 +05:30
parent f37291196b
commit 12044c6ea6
4 changed files with 46 additions and 1 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
+15
View File
@@ -0,0 +1,15 @@
{
"name": "Pascar Text Editor",
"short_name": "Pascar",
"start_url": "index.html",
"display": "standalone",
"background_color": "#1c1c1c",
"theme_color": "#295991",
"icons": [
{
"src": "icon-192.png",
"sizes": "192x192",
"type": "image/png"
}
]
}
+9
View File
@@ -1324,6 +1324,15 @@
e.returnValue = ''; e.returnValue = '';
} }
}); });
// -- Service Worker to make this application work offline
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('sw.js')
.then(reg => console.log('Service Worker Registered'))
.catch(err => console.log('Registration Failed', err));
});
}
})(); })();
</script> </script>
+21
View File
@@ -0,0 +1,21 @@
const CACHE_NAME = 'pascar';
const ASSETS = [
'index.html',
'manifest.json'
];
// Install: Cache the files
self.addEventListener('install', (e) => {
e.waitUntil(
caches.open(CACHE_NAME).then((cache) => cache.addAll(ASSETS))
);
});
// Fetch: Serve from cache if offline
self.addEventListener('fetch', (e) => {
e.respondWith(
caches.match(e.request).then((response) => {
return response || fetch(e.request);
})
);
});