fix: serve internal JS from path containing build ID (#2753)
Previously imported chunks were not cached at all. They are now cached properly with immutable cache headers.
This commit is contained in:
@@ -61,26 +61,30 @@ export function staticFiles<T>(): MiddlewareFn<T> {
|
||||
vary: "If-None-Match",
|
||||
});
|
||||
|
||||
if (cacheKey === null || ctx.config.mode === "development") {
|
||||
const ifNoneMatch = req.headers.get("If-None-Match");
|
||||
if (
|
||||
ifNoneMatch !== null &&
|
||||
(ifNoneMatch === etag || ifNoneMatch === `W/"${etag}"`)
|
||||
) {
|
||||
file.close();
|
||||
return new Response(null, { status: 304, headers });
|
||||
} else if (etag !== null) {
|
||||
headers.set("Etag", `W/"${etag}"`);
|
||||
}
|
||||
|
||||
if (
|
||||
ctx.config.mode !== "development" &&
|
||||
(BUILD_ID === cacheKey ||
|
||||
url.pathname.startsWith(
|
||||
`${ctx.config.basePath}/_fresh/js/${BUILD_ID}/`,
|
||||
))
|
||||
) {
|
||||
headers.append("Cache-Control", "public, max-age=31536000, immutable");
|
||||
} else {
|
||||
headers.append(
|
||||
"Cache-Control",
|
||||
"no-cache, no-store, max-age=0, must-revalidate",
|
||||
);
|
||||
} else {
|
||||
const ifNoneMatch = req.headers.get("If-None-Match");
|
||||
if (
|
||||
ifNoneMatch !== null &&
|
||||
(ifNoneMatch === etag || ifNoneMatch === `W/"${etag}"`)
|
||||
) {
|
||||
file.close();
|
||||
return new Response(null, { status: 304, headers });
|
||||
} else if (etag !== null) {
|
||||
headers.set("Etag", `W/"${etag}"`);
|
||||
}
|
||||
}
|
||||
|
||||
if (BUILD_ID === cacheKey) {
|
||||
headers.append("Cache-Control", "public, max-age=31536000, immutable");
|
||||
}
|
||||
|
||||
headers.set("Content-Length", String(file.size));
|
||||
|
||||
Reference in New Issue
Block a user