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:
Luca Casonato
2024-11-08 11:44:15 +01:00
committed by GitHub
parent 96e520a352
commit 6b685dde9f
6 changed files with 42 additions and 27 deletions
+3 -3
View File
@@ -14,7 +14,7 @@ import {
setRenderState,
} from "./runtime/server/preact_hooks.tsx";
import { DEV_ERROR_OVERLAY_URL } from "./constants.ts";
import { asset } from "./runtime/shared.ts";
import { BUILD_ID } from "./runtime/build_id.ts";
export interface Island {
file: string | URL;
@@ -240,13 +240,13 @@ function preactRender<State, Data>(
} finally {
// Add preload headers
const basePath = ctx.config.basePath;
const runtimeUrl = asset(`${basePath}/fresh-runtime.js`);
const runtimeUrl = `${basePath}/_fresh/js/${BUILD_ID}/fresh-runtime.js`;
let link = `<${encodeURI(runtimeUrl)}>; rel="modulepreload"; as="script"`;
state.islands.forEach((island) => {
const chunk = buildCache.getIslandChunkName(island.name);
if (chunk !== null) {
link += `, <${
encodeURI(asset(`${basePath}${chunk}`))
encodeURI(`${basePath}${chunk}`)
}>; rel="modulepreload"; as="script"`;
}
});