fix: service worker caching and ghostscript loader path issues
This commit is contained in:
14
package-lock.json
generated
14
package-lock.json
generated
@@ -76,6 +76,7 @@
|
||||
"@types/pdfkit": "^0.17.3",
|
||||
"@types/sortablejs": "^1.15.8",
|
||||
"@types/utif": "^3.0.6",
|
||||
"@vitejs/plugin-basic-ssl": "^2.1.4",
|
||||
"@vitest/coverage-v8": "^3.2.4",
|
||||
"@vitest/ui": "^3.2.4",
|
||||
"eslint": "^9.39.2",
|
||||
@@ -3932,6 +3933,19 @@
|
||||
"dev": true,
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/@vitejs/plugin-basic-ssl": {
|
||||
"version": "2.1.4",
|
||||
"resolved": "https://registry.npmjs.org/@vitejs/plugin-basic-ssl/-/plugin-basic-ssl-2.1.4.tgz",
|
||||
"integrity": "sha512-HXciTXN/sDBYWgeAD4V4s0DN0g72x5mlxQhHxtYu3Tt8BLa6MzcJZUyDVFCdtjNs3bfENVHVzOsmooTVuNgAAw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": "^18.0.0 || ^20.0.0 || >=22.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"vite": "^6.0.0 || ^7.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@vitest/coverage-v8": {
|
||||
"version": "3.2.4",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/coverage-v8/-/coverage-v8-3.2.4.tgz",
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
"@types/pdfkit": "^0.17.3",
|
||||
"@types/sortablejs": "^1.15.8",
|
||||
"@types/utif": "^3.0.6",
|
||||
"@vitejs/plugin-basic-ssl": "^2.1.4",
|
||||
"@vitest/coverage-v8": "^3.2.4",
|
||||
"@vitest/ui": "^3.2.4",
|
||||
"eslint": "^9.39.2",
|
||||
|
||||
50
public/sw.js
50
public/sw.js
@@ -146,12 +146,20 @@ async function cacheFirstStrategyWithDedup(request, isCDN) {
|
||||
const networkResponse = await fetch(request);
|
||||
|
||||
if (networkResponse && networkResponse.status === 200) {
|
||||
const clone = networkResponse.clone();
|
||||
const buffer = await clone.arrayBuffer();
|
||||
if (buffer.byteLength > 0) {
|
||||
const cache = await caches.open(CACHE_NAME);
|
||||
|
||||
await removeDuplicateCache(cache, fileName, isCDN);
|
||||
|
||||
await cache.put(request, networkResponse.clone());
|
||||
// console.log(`💾 [Cached from ${isCDN ? 'CDN' : 'local'}] Saved:`, fileName);
|
||||
await cache.put(
|
||||
request,
|
||||
new Response(buffer, {
|
||||
status: networkResponse.status,
|
||||
statusText: networkResponse.statusText,
|
||||
headers: networkResponse.headers,
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return networkResponse;
|
||||
@@ -166,9 +174,19 @@ async function cacheFirstStrategyWithDedup(request, isCDN) {
|
||||
try {
|
||||
const fallbackResponse = await fetch(localUrl);
|
||||
if (fallbackResponse && fallbackResponse.status === 200) {
|
||||
const fbClone = fallbackResponse.clone();
|
||||
const fbBuffer = await fbClone.arrayBuffer();
|
||||
if (fbBuffer.byteLength > 0) {
|
||||
const cache = await caches.open(CACHE_NAME);
|
||||
await cache.put(localUrl, fallbackResponse.clone());
|
||||
// console.log('✅ [Fallback Success] Cached local version:', fileName);
|
||||
await cache.put(
|
||||
localUrl,
|
||||
new Response(fbBuffer, {
|
||||
status: fallbackResponse.status,
|
||||
statusText: fallbackResponse.statusText,
|
||||
headers: fallbackResponse.headers,
|
||||
})
|
||||
);
|
||||
}
|
||||
return fallbackResponse;
|
||||
}
|
||||
} catch (fallbackError) {
|
||||
@@ -187,9 +205,14 @@ async function findCachedFile(fileName, requestUrl) {
|
||||
const cache = await caches.open(CACHE_NAME);
|
||||
|
||||
const exactMatch = await cache.match(requestUrl);
|
||||
if (exactMatch && exactMatch.headers.get('content-length') !== '0') {
|
||||
if (exactMatch) {
|
||||
const clone = exactMatch.clone();
|
||||
const buffer = await clone.arrayBuffer();
|
||||
if (buffer.byteLength > 0) {
|
||||
return exactMatch;
|
||||
}
|
||||
await cache.delete(requestUrl);
|
||||
}
|
||||
|
||||
const requests = await cache.keys();
|
||||
for (const req of requests) {
|
||||
@@ -234,8 +257,19 @@ async function networkFirstStrategy(request) {
|
||||
const networkResponse = await fetch(request);
|
||||
|
||||
if (networkResponse && networkResponse.status === 200) {
|
||||
const clone = networkResponse.clone();
|
||||
const buffer = await clone.arrayBuffer();
|
||||
if (buffer.byteLength > 0) {
|
||||
const cache = await caches.open(CACHE_NAME);
|
||||
cache.put(request, networkResponse.clone());
|
||||
cache.put(
|
||||
request,
|
||||
new Response(buffer, {
|
||||
status: networkResponse.status,
|
||||
statusText: networkResponse.statusText,
|
||||
headers: networkResponse.headers,
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return networkResponse;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { defineConfig, Plugin } from 'vitest/config';
|
||||
import type { IncomingMessage, ServerResponse } from 'http';
|
||||
import type { Connect } from 'vite';
|
||||
import basicSsl from '@vitejs/plugin-basic-ssl';
|
||||
import tailwindcss from '@tailwindcss/vite';
|
||||
import { nodePolyfills } from 'vite-plugin-node-polyfills';
|
||||
import { viteStaticCopy } from 'vite-plugin-static-copy';
|
||||
@@ -283,6 +284,7 @@ export default defineConfig(() => {
|
||||
return {
|
||||
base: (process.env.BASE_URL || '/').replace(/\/?$/, '/'),
|
||||
plugins: [
|
||||
// basicSsl(),
|
||||
handlebars({
|
||||
partialDirectory: resolve(__dirname, 'src/partials'),
|
||||
context: {
|
||||
|
||||
Reference in New Issue
Block a user