From 59c7a108028d6c2a83f1724bf62c5686685a22e6 Mon Sep 17 00:00:00 2001 From: Matthew Huebert Date: Thu, 12 Dec 2024 20:30:51 +0100 Subject: [PATCH] caching: better checks for HTML requests --- private-website-cache/src/worker.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/private-website-cache/src/worker.js b/private-website-cache/src/worker.js index c1f06c8..26044f9 100644 --- a/private-website-cache/src/worker.js +++ b/private-website-cache/src/worker.js @@ -11,12 +11,18 @@ const CACHE_POLICIES = { }; const getCachePolicy = (pathname, contentType) => { + // Handle root-like paths first + if (pathname === '/' || pathname.endsWith('/') || !pathname.includes('.')) { + return CACHE_POLICIES.HTML; + } + const ext = pathname.split('.').pop().toLowerCase(); if (['wasm', 'data'].includes(ext)) { return CACHE_POLICIES.LARGE_BINARY; } - if (contentType?.includes('text/html')) { + // More specific content type check + if (contentType?.toLowerCase().includes('text/html')) { return CACHE_POLICIES.HTML; } return CACHE_POLICIES.STATIC;