Skip to content

Commit a544104

Browse files
HeyItsGilbertclaude
andcommitted
perf: defer non-critical CSS and extend cache headers
Targets the render-blocking and cache-lifetime Unlighthouse findings: - baseof.html: Font Awesome, Prism, alerts, code-copy, and Algolia stylesheets now load via the print-media swap (media=print + onload) instead of blocking first paint. Only the critical fingerprinted Tailwind bundle remains render-blocking. A <noscript> block preserves the blocking links when JS is disabled. - netlify.toml: add Cache-Control for fonts (immutable 1y, they are content-hashed) and images (30d, not fingerprinted). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent b36247b commit a544104

2 files changed

Lines changed: 64 additions & 6 deletions

File tree

netlify.toml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,50 @@
2929
for = "/*.js"
3030
[headers.values]
3131
Cache-Control = "public, max-age=31536000, immutable"
32+
33+
# Fonts are fingerprinted by Hugo (content hash in filename) — safe to cache forever.
34+
[[headers]]
35+
for = "/*.ttf"
36+
[headers.values]
37+
Cache-Control = "public, max-age=31536000, immutable"
38+
39+
[[headers]]
40+
for = "/*.woff2"
41+
[headers.values]
42+
Cache-Control = "public, max-age=31536000, immutable"
43+
44+
# Images are not fingerprinted — cache for 30 days without immutable so updates propagate.
45+
[[headers]]
46+
for = "/*.png"
47+
[headers.values]
48+
Cache-Control = "public, max-age=2592000"
49+
50+
[[headers]]
51+
for = "/*.jpg"
52+
[headers.values]
53+
Cache-Control = "public, max-age=2592000"
54+
55+
[[headers]]
56+
for = "/*.jpeg"
57+
[headers.values]
58+
Cache-Control = "public, max-age=2592000"
59+
60+
[[headers]]
61+
for = "/*.svg"
62+
[headers.values]
63+
Cache-Control = "public, max-age=2592000"
64+
65+
[[headers]]
66+
for = "/*.webp"
67+
[headers.values]
68+
Cache-Control = "public, max-age=2592000"
69+
70+
[[headers]]
71+
for = "/*.gif"
72+
[headers.values]
73+
Cache-Control = "public, max-age=2592000"
74+
75+
[[headers]]
76+
for = "/*.ico"
77+
[headers.values]
78+
Cache-Control = "public, max-age=2592000"

themes/powershell-community/layouts/_default/baseof.html

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,25 @@
8686
{{ if .IsHome }}{{ partial "schema-site.html" . }}{{ end }}
8787
{{ if and .IsPage (in (slice "articles" "podcast") .Section) }}{{ partial "schema-article.html" . }}{{ end }}
8888

89-
<!-- CSS — Tailwind purged against the built site, minified + fingerprinted -->
89+
<!-- Critical CSS — Tailwind purged against the built site, minified + fingerprinted (render-blocking by design) -->
9090
{{ $tailwind := resources.Get "css/tailwind.css" | minify | fingerprint }}
9191
<link href="{{ $tailwind.RelPermalink }}" rel="stylesheet">
92-
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
93-
<link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/themes/prism-tomorrow.min.css" rel="stylesheet">
94-
<link href="/css/alerts.css" rel="stylesheet">
95-
<link href="/css/code-copy.css" rel="stylesheet">
96-
{{ with .Site.Params.algolia }}<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@algolia/algoliasearch-netlify-frontend@1/dist/algoliasearchNetlify.css" />{{ end }}
92+
93+
<!-- Non-critical CSS — loaded async via the print-media swap so it doesn't block first paint -->
94+
{{- $asyncCSS := slice
95+
"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css"
96+
"https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/themes/prism-tomorrow.min.css"
97+
"/css/alerts.css"
98+
"/css/code-copy.css" -}}
99+
{{- with .Site.Params.algolia }}{{ $asyncCSS = $asyncCSS | append "https://cdn.jsdelivr.net/npm/@algolia/algoliasearch-netlify-frontend@1/dist/algoliasearchNetlify.css" }}{{ end -}}
100+
{{ range $asyncCSS }}
101+
<link rel="stylesheet" href="{{ . }}" media="print" onload="this.media='all'">
102+
{{- end }}
103+
<noscript>
104+
{{- range $asyncCSS }}
105+
<link rel="stylesheet" href="{{ . }}">
106+
{{- end }}
107+
</noscript>
97108

98109
<!-- Self-hosted Inter (replaces render-blocking Google Fonts @import) -->
99110
<style>

0 commit comments

Comments
 (0)