feature (loadspeed): optimise load speed

This commit is contained in:
MickaelK 2025-09-23 12:28:51 +10:00
parent 99d539929e
commit 6299f8776f
2 changed files with 24 additions and 16 deletions

View file

@ -1,13 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<base href="{{ .base }}">
<meta charset="UTF-8">
<title></title>
<base href="{{ .base }}">
{{- range .bundle }}
<link rel="modulepreload" href="{{ . }}" />
{{- end }}
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="application-name" content="Filestash">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1">
<title></title>
<link rel="icon" href="{{ .favicon }}">
<script>{{ if eq .license "agpl" }}{{ template "loader-cat" }}{{ else }}{{ template "loader-basic" }}{{ end }}</script>
</head>
<body>
@ -34,16 +36,15 @@
<script type="module">
async function ignitionSequence() {
window.VERSION = "{{ slice .version 0 7 }}::{{ .hash }}";
try {
if (!HTMLScriptElement.supports?.("importmap")) throw new Error("fastboot is not supported on this platform");
{{ load_asset "assets/boot/bundler_init.js" }}
await Promise.all(Array({{ .bundle_size }}).fill().map((_, i) => new Promise((resolve, reject) => document.head.appendChild(Object.assign(document.createElement("script"), {
type: "module",
src: `./assets/bundle.js?version=${window.VERSION}&chunk=${i+1}`,
onload: resolve,
onerror: reject,
await Promise.all([
{{- range .bundle }}
"{{ . }}",
{{- end }}
].map((src) => new Promise((onload, onerror) => document.head.appendChild(Object.assign(document.createElement("script"), {
type: "module", src, onload, onerror,
})))));
{{ load_asset "assets/boot/bundler_complete.js" }}
} catch (err) { console.error(err); }

View file

@ -239,12 +239,19 @@ func ServeIndex(indexPath string) func(*App, http.ResponseWriter, *http.Request)
sign := signature()
base := WithBase("/")
templateData := map[string]any{
"base": base,
"version": BUILD_REF,
"license": LICENSE,
"hash": sign,
"favicon": favicon(),
"bundle_size": len(preload),
"base": base,
"version": BUILD_REF,
"license": LICENSE,
"hash": sign,
"favicon": favicon(),
"bundle": func() []string {
b := make([]string, len(preload))
v := BUILD_REF[0:7] + "::" + sign
for i := 0; i < len(preload); i++ {
b[i] = fmt.Sprintf("./assets/bundle.js?version=%s&chunk=%d", v, i+1)
}
return b
}(),
}
calculatedEtag := QuickHash(base+BUILD_REF+LICENSE+sign, 10)
head.Set("ETag", calculatedEtag)