Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/opencode/src/server/shared/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,18 @@ function notFound() {
return HttpServerResponse.jsonUnsafe({ error: "Not Found" }, { status: 404 })
}

// Vite content-hashed filenames contain a hash segment (e.g. index-abc123.js)
const HASHED_ASSET_REGEX = /[-.][\da-f]{8,}\.\w+$/

function cacheControl(file: string) {
if (AppFileSystem.mimeType(file).startsWith("text/html")) return "no-cache"
if (HASHED_ASSET_REGEX.test(file)) return "public, max-age=31536000, immutable"
return "public, max-age=3600"
}

function embeddedUIResponse(file: string, body: Uint8Array) {
const mime = AppFileSystem.mimeType(file)
const headers = new Headers({ "content-type": mime })
const headers = new Headers({ "content-type": mime, "cache-control": cacheControl(file) })
if (mime.startsWith("text/html")) {
headers.set("content-security-policy", cspForHtml(new TextDecoder().decode(body)))
}
Expand Down
Loading