fix(web): optimize serveMainHtml performance by processing HTML at startup

This commit is contained in:
yiling
2026-07-09 15:50:09 +08:00
parent c3d88bb972
commit d3bbd42208
+7 -11
View File
@@ -89,17 +89,13 @@ async function run() {
const mainHtmlHeaders = bundle.files.find((f) => f.path === bundle.index)?.headers || {
'content-type': 'text/html;charset=utf-8',
}
let mainHtmlText = ''
const serveMainHtml = async () => {
if (!mainHtmlText) {
const raw = await mainHtmlFile.text()
mainHtmlText = raw
.replaceAll('href="./', 'href="/')
.replaceAll('src="./', 'src="/')
.replaceAll('content="./', 'content="/')
}
return new Response(mainHtmlText, { headers: mainHtmlHeaders })
}
const raw = await mainHtmlFile.text()
const mainHtmlText = raw
.replaceAll('href="./', 'href="/')
.replaceAll('src="./', 'src="/')
.replaceAll('content="./', 'content="/')
const serveMainHtml = () => new Response(mainHtmlText, { headers: mainHtmlHeaders })
routes['/'] = serveMainHtml
routes['/*'] = serveMainHtml