Skip to content

Commit 04b7077

Browse files
committed
chore: streamline wrangler configuration and enhance caching headers for static assets in worker script
1 parent c398351 commit 04b7077

3 files changed

Lines changed: 10 additions & 25 deletions

File tree

public/_headers

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
/_astro/*
2+
Cache-Control: public, max-age=31536000, immutable
3+
14
/assets/*
25
Cache-Control: public, max-age=31536000, immutable
36

7+
/pagefind/*
8+
Cache-Control: public, max-age=31536000, immutable
9+
410
/*
511
Cache-Control: public, max-age=0, must-revalidate
612
X-Frame-Options: SAMEORIGIN

src/worker.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -357,23 +357,6 @@ export default {
357357
});
358358
}
359359

360-
const response = await env.ASSETS.fetch(request);
361-
if (!response.ok) return response;
362-
363-
const pathname = url.pathname;
364-
if (
365-
pathname.startsWith('/assets/') ||
366-
pathname.startsWith('/pagefind/') ||
367-
/\.(ico|png|svg|webp|woff2?|ttf|eot|webmanifest)(\?|$)/i.test(pathname)
368-
) {
369-
const headers = new Headers(response.headers);
370-
headers.set('Cache-Control', 'public, max-age=31536000, immutable');
371-
return new Response(response.body, {
372-
status: response.status,
373-
statusText: response.statusText,
374-
headers,
375-
});
376-
}
377-
return response;
360+
return env.ASSETS.fetch(request);
378361
},
379362
};

wrangler.jsonc

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,8 @@
99
"directory": "./dist",
1010
"binding": "ASSETS",
1111
"html_handling": "force-trailing-slash",
12-
"not_found_handling": "404-page"
12+
"not_found_handling": "404-page",
13+
"run_worker_first": ["/api/"]
1314
},
14-
"kv_namespaces": [
15-
{
16-
"binding": "MS_ISO_LINKS",
17-
"id": "5c778e1859c64276b5fe5b4291deb857"
18-
}
19-
]
15+
"kv_namespaces": [{ "binding": "MS_ISO_LINKS", "id": "5c778e1859c64276b5fe5b4291deb857" }]
2016
}

0 commit comments

Comments
 (0)