Skip to content

Commit fa9c7c1

Browse files
committed
perf(preview): avoid encoding html bodies for head requests
1 parent dc40419 commit fa9c7c1

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

‎apps/server/src/http.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,14 @@ export const assetFileResponse = Effect.fn("assetFileResponse")(function* (
191191
}
192192
const html = source === undefined ? undefined : injectHtmlRenderFocusStyles(source);
193193
if (html !== undefined) {
194-
const bytes = new TextEncoder().encode(html);
195194
headers["Cache-Control"] = "private, no-store";
195+
if (method === "HEAD") {
196+
headers["Content-Length"] = String(Buffer.byteLength(html, "utf8"));
197+
return HttpServerResponse.empty({ status: 200, headers });
198+
}
199+
const bytes = new TextEncoder().encode(html);
196200
headers["Content-Length"] = String(bytes.byteLength);
197-
return method === "HEAD"
198-
? HttpServerResponse.empty({ status: 200, headers })
199-
: HttpServerResponse.uint8Array(bytes, { headers });
201+
return HttpServerResponse.uint8Array(bytes, { headers });
200202
}
201203
}
202204
const mediaInfo = mediaFile ? yield* statMediaFile(asset.path, mediaFile) : undefined;

0 commit comments

Comments
 (0)