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 . .
|
||||
|
||||
# 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
|
||||
EXPOSE 3000
|
||||
|
||||
|
||||
@ -15,7 +15,8 @@ import {
|
||||
renderArchiveView,
|
||||
renderTimeOffHistoryView,
|
||||
updatePendingRequestsList,
|
||||
renderEditTimeOffModal
|
||||
renderEditTimeOffModal,
|
||||
renderCalendarView
|
||||
} from './ui.js';
|
||||
|
||||
// --- STATE MANAGEMENT ---
|
||||
@ -55,7 +56,7 @@ async function subscribeToNotifications() {
|
||||
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 (res.success) {
|
||||
@ -262,6 +263,9 @@ function handleAdminDashboardClick(e) {
|
||||
case 'view-notes-btn':
|
||||
handleViewNotesClick();
|
||||
return;
|
||||
case 'view-calendar-btn':
|
||||
renderCalendarView();
|
||||
return;
|
||||
}
|
||||
|
||||
if (target.classList.contains('approve-request-btn') || target.classList.contains('deny-request-btn')) {
|
||||
@ -463,6 +467,9 @@ function setupTabbedInterface() {
|
||||
panel.classList.add('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 = [
|
||||
'/', '/index.html', '/style/style.css', '/js/main.js', '/js/ui.js',
|
||||
'/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/')) {
|
||||
return;
|
||||
}
|
||||
|
||||
const url = new URL(event.request.url);
|
||||
|
||||
if (event.request.mode === 'navigate' || url.pathname === '/' || url.pathname.endsWith('/index.html')) {
|
||||
event.respondWith(
|
||||
caches.match(event.request).then(response => response || fetch(event.request))
|
||||
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(
|
||||
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