mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-04 06:54:28 +00:00
fix(web): optimize serveMainHtml performance by processing HTML at startup
This commit is contained in:
+7
-11
@@ -89,17 +89,13 @@ async function run() {
|
|||||||
const mainHtmlHeaders = bundle.files.find((f) => f.path === bundle.index)?.headers || {
|
const mainHtmlHeaders = bundle.files.find((f) => f.path === bundle.index)?.headers || {
|
||||||
'content-type': 'text/html;charset=utf-8',
|
'content-type': 'text/html;charset=utf-8',
|
||||||
}
|
}
|
||||||
let mainHtmlText = ''
|
const raw = await mainHtmlFile.text()
|
||||||
const serveMainHtml = async () => {
|
const mainHtmlText = raw
|
||||||
if (!mainHtmlText) {
|
.replaceAll('href="./', 'href="/')
|
||||||
const raw = await mainHtmlFile.text()
|
.replaceAll('src="./', 'src="/')
|
||||||
mainHtmlText = raw
|
.replaceAll('content="./', 'content="/')
|
||||||
.replaceAll('href="./', 'href="/')
|
const serveMainHtml = () => new Response(mainHtmlText, { headers: mainHtmlHeaders })
|
||||||
.replaceAll('src="./', 'src="/')
|
|
||||||
.replaceAll('content="./', 'content="/')
|
|
||||||
}
|
|
||||||
return new Response(mainHtmlText, { headers: mainHtmlHeaders })
|
|
||||||
}
|
|
||||||
|
|
||||||
routes['/'] = serveMainHtml
|
routes['/'] = serveMainHtml
|
||||||
routes['/*'] = serveMainHtml
|
routes['/*'] = serveMainHtml
|
||||||
|
|||||||
Reference in New Issue
Block a user