Add Caching

This commit is contained in:
2026-03-17 21:47:12 +01:00
parent 35930857fd
commit 32e914fdc1
17 changed files with 298 additions and 18 deletions
+13 -2
View File
@@ -6,6 +6,7 @@ import handleWebPages from "./web-pages/handle-web-pages";
import handleRoutes from "./handle-routes";
import isDevelopment from "../../utils/is-development";
import grabConstants from "../../utils/grab-constants";
import { AppData } from "../../data/app-data";
type Params = {
dev?: boolean;
@@ -15,6 +16,8 @@ export default async function (params?: Params): Promise<ServeOptions> {
const port = grabAppPort();
const { PUBLIC_DIR } = grabDirNames();
const is_dev = isDevelopment();
return {
async fetch(req, server) {
try {
@@ -34,7 +37,7 @@ export default async function (params?: Params): Promise<ServeOptions> {
}
}
if (url.pathname === "/__hmr" && isDevelopment()) {
if (url.pathname === "/__hmr" && is_dev) {
const referer_url = new URL(
req.headers.get("referer") || "",
);
@@ -95,7 +98,15 @@ export default async function (params?: Params): Promise<ServeOptions> {
),
);
return new Response(file);
let res_opts: ResponseInit = {};
if (!is_dev && url.pathname.match(/__bunext/)) {
res_opts.headers = {
"Cache-Control": `public, max-age=${AppData["BunextStaticFilesCacheExpiry"]}, must-revalidate`,
};
}
return new Response(file, res_opts);
}
if (url.pathname.startsWith("/favicon.")) {