From 01b24f830fc2f5bc97c717406e5ac5e68a5f252f Mon Sep 17 00:00:00 2001 From: schreifuchs Date: Sun, 8 Mar 2026 01:05:57 +0100 Subject: [PATCH] chore: better resource loading --- internal/components/page/html.go | 7 +++++-- internal/components/page/page.go | 3 --- internal/components/translate/context.go | 2 +- package.json | 3 ++- pnpm-lock.yaml | 10 ++++++++++ web/components/imagetile.templ | 1 + web/layouts/base.templ | 6 +++--- web/layouts/render.go | 2 +- web/pages/index.templ | 2 +- web/static/css/output.css | 2 +- web/static/js/preload.min.js | 1 + 11 files changed, 26 insertions(+), 13 deletions(-) create mode 100644 web/static/js/preload.min.js diff --git a/internal/components/page/html.go b/internal/components/page/html.go index c1d97fc..fa2820e 100644 --- a/internal/components/page/html.go +++ b/internal/components/page/html.go @@ -55,8 +55,11 @@ func imageMiddleware(page PageHeader) func(w io.Writer, node ast.Node, entering } img.Attribute = &ast.Attribute{Attrs: map[string][]byte{ - "srcset": []byte(images.SourceSet(src)), - "src": []byte(src), + "srcset": []byte(images.SourceSet(src)), + "fetchpriority": []byte("low"), + "loading": []byte("lazy"), + "class": []byte("min-h-48"), + "src": []byte(src), }} // // img.Attrs["srcset"] = diff --git a/internal/components/page/page.go b/internal/components/page/page.go index d9a7aa8..4b64089 100644 --- a/internal/components/page/page.go +++ b/internal/components/page/page.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "log/slog" "regexp" "strings" @@ -57,8 +56,6 @@ func (s *Service) getPageHeaders(ctx context.Context, uid string) (page PageHead } } - slog.Debug("loaded page infos", "cover", coverImage, "content", contentMD) - page.md, err = s.fs.Read(contentMD.Path()) if err != nil { return diff --git a/internal/components/translate/context.go b/internal/components/translate/context.go index c9a3750..ab9efce 100644 --- a/internal/components/translate/context.go +++ b/internal/components/translate/context.go @@ -65,7 +65,7 @@ func PathForLang(ctx context.Context, lang string, pp ...string) string { } } - return path.Join(append([]string{lang}, pp...)...) + return "/" + path.Join(append([]string{lang}, pp...)...) } func (s *Service) SupportedLanguages() (languages []string) { diff --git a/package.json b/package.json index 8d62f79..18d8661 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "build:css": "tailwindcss -i ./web/static/css/input.css -o ./web/static/css/output.css --minify", "watch:css": "tailwindcss -i ./web/static/css/input.css -o ./web/static/css/output.css --watch", - "build:js": "cp node_modules/htmx.org/dist/htmx.min.js web/static/js/htmx.min.js" + "build:js": "cp node_modules/htmx.org/dist/htmx.min.js web/static/js/htmx.min.js && cp ./node_modules/htmx-ext-preload/dist/preload.min.js ./web/static/js/preload.min.js" }, "keywords": [], "author": "", @@ -20,6 +20,7 @@ "tailwindcss": "^4.1.18" }, "dependencies": { + "htmx-ext-preload": "^2.1.2", "htmx.org": "^2.0.8" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f00d447..3b64bdd 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,6 +8,9 @@ importers: .: dependencies: + htmx-ext-preload: + specifier: ^2.1.2 + version: 2.1.2 htmx.org: specifier: ^2.0.8 version: 2.0.8 @@ -277,6 +280,9 @@ packages: graceful-fs@4.2.11: resolution: {integrity: sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==} + htmx-ext-preload@2.1.2: + resolution: {integrity: sha512-foD06XAITUUQApCUQnPexyJ6B7+4vFGMQ+t42unTVTGRu/CYHdAAt6oHg7eekPHT7NRnbM5hjnGVKtClryPabg==} + htmx.org@2.0.8: resolution: {integrity: sha512-fm297iru0iWsNJlBrjvtN7V9zjaxd+69Oqjh4F/Vq9Wwi2kFisLcrLCiv5oBX0KLfOX/zG8AUo9ROMU5XUB44Q==} @@ -617,6 +623,10 @@ snapshots: graceful-fs@4.2.11: {} + htmx-ext-preload@2.1.2: + dependencies: + htmx.org: 2.0.8 + htmx.org@2.0.8: {} is-extglob@2.1.1: {} diff --git a/web/components/imagetile.templ b/web/components/imagetile.templ index 0590c0d..7febf0a 100644 --- a/web/components/imagetile.templ +++ b/web/components/imagetile.templ @@ -8,6 +8,7 @@ templ ImageTile(src string) { src={ src } srcset={ images.SourceSet(src) } fetchpriority="high" + loading="eager" class="row-start-1 col-start-1 pointer-events-none w-full h-96 object-cover" />
diff --git a/web/layouts/base.templ b/web/layouts/base.templ index 59593fd..26d11c5 100644 --- a/web/layouts/base.templ +++ b/web/layouts/base.templ @@ -14,17 +14,17 @@ templ Base(title string) { - +
- schreifuchs.ch + schreifuchs.ch