[code] created app.js and service-worker.js, these files are key for offline and PWA functionality, also updated all project HTML files to reflect these new files and their relevant links.

This commit is contained in:
2026-04-23 20:52:06 +01:00
parent 5d5daf535c
commit 8ffd91564f
5 changed files with 51 additions and 0 deletions

8
app.js Normal file
View File

@@ -0,0 +1,8 @@
if ('serviceWorker' in navigator) { // Setup — initialises and adds service worker to page
window.addEventListener('load', () => {
navigator.serviceWorker
.register('/service-worker.js')
.then(reg => console.log('Service worker registered:', reg.scope))
.catch(err => console.error('Registration failed:', err));
});
}

View File

@@ -7,6 +7,7 @@
<link rel="icon" type="image/x-icon" href="/assets/icons/favicon.ico"> <link rel="icon" type="image/x-icon" href="/assets/icons/favicon.ico">
<link rel="stylesheet" href="/css/styles.css"> <link rel="stylesheet" href="/css/styles.css">
<link rel="manifest" href="/manifest.json" /> <link rel="manifest" href="/manifest.json" />
<script src="/app.js" defer></script>
</head> </head>
<body> <body>
</body> </body>

View File

@@ -7,6 +7,7 @@
<link rel="icon" type="image/x-icon" href="/assets/icons/favicon.ico"> <link rel="icon" type="image/x-icon" href="/assets/icons/favicon.ico">
<link rel="stylesheet" href="/css/styles.css"> <link rel="stylesheet" href="/css/styles.css">
<link rel="manifest" href="/manifest.json" /> <link rel="manifest" href="/manifest.json" />
<script src="/app.js" defer></script>
</head> </head>
<body> <body>
<div class="loginPane"> <div class="loginPane">

View File

@@ -7,6 +7,7 @@
<link rel="icon" type="image/x-icon" href="/assets/icons/favicon.ico"> <link rel="icon" type="image/x-icon" href="/assets/icons/favicon.ico">
<link rel="stylesheet" href="/css/styles.css"> <link rel="stylesheet" href="/css/styles.css">
<link rel="manifest" href="/manifest.json" /> <link rel="manifest" href="/manifest.json" />
<script src="/app.js" defer></script>
</head> </head>
<body> <body>
</body> </body>

40
service-worker.js Normal file
View File

@@ -0,0 +1,40 @@
// This was created/generated by Claude AI LLM there may be errors present.
const CACHE_NAME = 'sentinel-v1';
const ASSETS = [
'/',
'/html/home.html',
'/html/login.html',
'/html/transport.html',
'/app.js',
'/manifest.json',
'/css/styles.css',
'/css/loader.css',
'/assets/icons/favicon.ico',
'/assets/images/sentinelLogo.png',
];
// Install — cache your core assets
self.addEventListener('install', event => {
event.waitUntil(
caches.open(CACHE_NAME).then(cache => cache.addAll(ASSETS))
);
});
// Activate — clean up old caches
self.addEventListener('activate', event => {
event.waitUntil(
caches.keys().then(keys =>
Promise.all(
keys.filter(key => key !== CACHE_NAME).map(key => caches.delete(key))
)
)
);
});
// Fetch — serve from cache, fall back to network
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request).then(cached => cached || fetch(event.request))
);
});