all repos — website @ 7c64360212a54cf259c503929c74c6c92c4d875d

My website

Reduce memory usage by not duplicating default headers
Alan Pearce alan@alanpearce.eu
Wed, 13 Sep 2023 06:04:08 +0200
commit

7c64360212a54cf259c503929c74c6c92c4d875d

parent

b89c78af528b400d31ce59576fc4238b902a9cfe

1 files changed, 3 insertions(+), 3 deletions(-)

jump to
M src/index.tssrc/index.ts
@@ -19,7 +19,7 @@ } 
 type File = {
   filename: string;
-  headers: Record<string, string>;
+  headers?: Record<string, string>;
   size: number;
   mtime: string;
 };
@@ -37,7 +37,7 @@ filename,     headers:
       pathname === "/404.html"
         ? Object.assign({}, defaultHeaders, { "cache-control": "no-cache" })
-        : defaultHeaders,
+        : undefined,
     size: stat.size,
     mtime: stat.mtime.toUTCString(),
   });
@@ -72,7 +72,7 @@ statusCode: number = 200, ): Promise<Response> {
   if (file && (await fsp.exists(file.filename))) {
     return new Response(Bun.file(file.filename), {
-      headers: file.headers,
+      headers: file.headers || defaultHeaders,
       status: statusCode,
     });
   } else {