chore: version service worker cache
This commit is contained in:
parent
eca6f4ece8
commit
3784ec7ca7
@ -13,6 +13,10 @@ RUN npm install --omit=dev
|
|||||||
# Copy all project files, including the 'public' directory, into the container
|
# Copy all project files, including the 'public' directory, into the container
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
|
# Bake a cache-busting version into the service worker
|
||||||
|
ARG APP_VERSION=dev
|
||||||
|
RUN sed -i "s/__APP_VERSION__/${APP_VERSION}/g" public/sw.js
|
||||||
|
|
||||||
# Make port 3000 available
|
# Make port 3000 available
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
|
|||||||
@ -15,7 +15,8 @@ import {
|
|||||||
renderArchiveView,
|
renderArchiveView,
|
||||||
renderTimeOffHistoryView,
|
renderTimeOffHistoryView,
|
||||||
updatePendingRequestsList,
|
updatePendingRequestsList,
|
||||||
renderEditTimeOffModal
|
renderEditTimeOffModal,
|
||||||
|
renderCalendarView
|
||||||
} from './ui.js';
|
} from './ui.js';
|
||||||
|
|
||||||
// --- STATE MANAGEMENT ---
|
// --- STATE MANAGEMENT ---
|
||||||
@ -55,7 +56,7 @@ async function subscribeToNotifications() {
|
|||||||
applicationServerKey: urlBase64ToUint8Array(publicVapidKey)
|
applicationServerKey: urlBase64ToUint8Array(publicVapidKey)
|
||||||
});
|
});
|
||||||
|
|
||||||
const res = await apiCall(' /subscribe', 'POST', subscription);
|
const res = await apiCall('/subscribe', 'POST', subscription);
|
||||||
|
|
||||||
// If the subscription is saved successfully, set a flag so we don't do it again
|
// If the subscription is saved successfully, set a flag so we don't do it again
|
||||||
if (res.success) {
|
if (res.success) {
|
||||||
@ -262,6 +263,9 @@ function handleAdminDashboardClick(e) {
|
|||||||
case 'view-notes-btn':
|
case 'view-notes-btn':
|
||||||
handleViewNotesClick();
|
handleViewNotesClick();
|
||||||
return;
|
return;
|
||||||
|
case 'view-calendar-btn':
|
||||||
|
renderCalendarView();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target.classList.contains('approve-request-btn') || target.classList.contains('deny-request-btn')) {
|
if (target.classList.contains('approve-request-btn') || target.classList.contains('deny-request-btn')) {
|
||||||
@ -463,6 +467,9 @@ function setupTabbedInterface() {
|
|||||||
panel.classList.add('hidden');
|
panel.classList.add('hidden');
|
||||||
});
|
});
|
||||||
document.getElementById(`tab-content-${tabTarget}`).classList.remove('hidden');
|
document.getElementById(`tab-content-${tabTarget}`).classList.remove('hidden');
|
||||||
|
if (tabTarget === 'calendar') {
|
||||||
|
renderCalendarView();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
32
public/sw.js
32
public/sw.js
@ -1,6 +1,7 @@
|
|||||||
// public/sw.js - CORRECTED
|
// public/sw.js
|
||||||
|
|
||||||
const CACHE_NAME = 'timepulse-v1';
|
const APP_VERSION = '__APP_VERSION__';
|
||||||
|
const CACHE_NAME = `timepulse-${APP_VERSION}`;
|
||||||
const filesToCache = [
|
const filesToCache = [
|
||||||
'/', '/index.html', '/style/style.css', '/js/main.js', '/js/ui.js',
|
'/', '/index.html', '/style/style.css', '/js/main.js', '/js/ui.js',
|
||||||
'/js/api.js', '/js/utils.js', '/manifest.json',
|
'/js/api.js', '/js/utils.js', '/manifest.json',
|
||||||
@ -32,8 +33,33 @@ self.addEventListener('fetch', event => {
|
|||||||
if (event.request.method !== 'GET' || event.request.url.includes('/api/')) {
|
if (event.request.method !== 'GET' || event.request.url.includes('/api/')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const url = new URL(event.request.url);
|
||||||
|
|
||||||
|
if (event.request.mode === 'navigate' || url.pathname === '/' || url.pathname.endsWith('/index.html')) {
|
||||||
|
event.respondWith(
|
||||||
|
fetch(event.request)
|
||||||
|
.then(response => {
|
||||||
|
const responseClone = response.clone();
|
||||||
|
caches.open(CACHE_NAME).then(cache => cache.put(event.request, responseClone));
|
||||||
|
return response;
|
||||||
|
})
|
||||||
|
.catch(() => caches.match(event.request))
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
event.respondWith(
|
event.respondWith(
|
||||||
caches.match(event.request).then(response => response || fetch(event.request))
|
caches.match(event.request).then(cached => {
|
||||||
|
const fetchPromise = fetch(event.request).then(response => {
|
||||||
|
if (response && response.ok) {
|
||||||
|
const responseClone = response.clone();
|
||||||
|
caches.open(CACHE_NAME).then(cache => cache.put(event.request, responseClone));
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
});
|
||||||
|
return cached || fetchPromise;
|
||||||
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user