Skip to content

Commit

Permalink
caching: better checks for HTML requests
Browse files Browse the repository at this point in the history
  • Loading branch information
mhuebert committed Dec 12, 2024
1 parent 2293986 commit 59c7a10
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion private-website-cache/src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 59c7a10

Please sign in to comment.