Skip to content

fix: preload Google Fonts to reduce layout shift#1215

Merged
CaiJimmy merged 3 commits into
CaiJimmy:masterfrom
delize:fix-font-display-swap
Feb 17, 2026
Merged

fix: preload Google Fonts to reduce layout shift#1215
CaiJimmy merged 3 commits into
CaiJimmy:masterfrom
delize:fix-font-display-swap

Conversation

@delize
Copy link
Copy Markdown
Contributor

@delize delize commented Dec 24, 2025

Move font loading from footer JS to head with preconnect and preload hints.

This reduces CLS by ensuring fonts load earlier in the page lifecycle instead of being dynamically inserted after footer loads.

This was noticed while trying to do #1214 and the text kept resizing the layout whenever I would hard refresh. Now the swap isn't as bad when loading the fonts and hard refreshing or on first page load.

Only other way to fix it would be to host the fonts ourselves.

delize and others added 3 commits December 23, 2025 19:30
Move font loading from footer JS to head with preconnect and preload
hints. This reduces CLS by ensuring fonts load earlier in the page
lifecycle instead of being dynamically inserted after footer loads.
Copy link
Copy Markdown
Owner

@CaiJimmy CaiJimmy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I don't actually remember exactly why it was done this way instead of using a normal style tag and preload. Maybe it's because, back in 2020, this was the recommended method for avoiding Google Font CSS blocking.

@CaiJimmy CaiJimmy merged commit 0cefe05 into CaiJimmy:master Feb 17, 2026
powerfullz pushed a commit to powerfullz/hugo-theme-stack-upstream that referenced this pull request Mar 10, 2026
* fix: preload Google Fonts to reduce layout shift

Move font loading from footer JS to head with preconnect and preload
hints. This reduces CLS by ensuring fonts load earlier in the page
lifecycle instead of being dynamically inserted after footer loads.

* style: reorder custom font inclusion in head template

---------

Co-authored-by: delize <4028612+delize@users.noreply.github.com>
Co-authored-by: Jimmy Cai <jimmy@cai.im>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants