Skip to content

Commit ad2bdfb

Browse files
johanrinclaude
andcommitted
Add image preloading for faster LCP
Preloads cover images to improve Largest Contentful Paint score. Handles both site-level images and page bundle images correctly. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 2423bbf commit ad2bdfb

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

layouts/partials/custom-head.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,23 @@
44
<link rel="dns-prefetch" href="https://www.googletagmanager.com" />
55
<link rel="dns-prefetch" href="https://www.google-analytics.com" />
66

7+
{{/* Preload cover images for faster LCP */}}
8+
{{- $imageURL := "" -}}
9+
{{- if .Params.images -}}
10+
{{- $img := index .Params.images 0 -}}
11+
{{- if eq .Kind "page" -}}
12+
{{/* For page bundles, image is relative to the page */}}
13+
{{- $imageURL = printf "%s%s" .Permalink $img -}}
14+
{{- else -}}
15+
{{- $imageURL = $img | absURL -}}
16+
{{- end -}}
17+
{{- else if .Site.Params.images -}}
18+
{{- $imageURL = index .Site.Params.images 0 | absURL -}}
19+
{{- end -}}
20+
{{- if $imageURL -}}
21+
<link rel="preload" as="image" href="{{ $imageURL }}" />
22+
{{- end -}}
23+
724
{{/* Prevent 404 pages from being indexed */}}
825
{{ if eq .Kind "404" }}
926
<meta name="robots" content="noindex, nofollow" />

0 commit comments

Comments
 (0)