BLOG-92 feat: defer font loading to improve performance
All checks were successful
PR Title Check / pr-title-check (pull_request) Successful in 16s
Frontend CI / build (push) Successful in 1m5s

This commit is contained in:
SquidSpirit 2025-08-02 15:25:29 +08:00
parent 48005d1f52
commit 1e1bae0812
2 changed files with 9 additions and 1 deletions

View File

@ -18,10 +18,10 @@
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
id="google-fonts"
href="https://fonts.googleapis.com/css2?family=Noto+Sans+Mono&family=Noto+Sans+TC:wght@100..900&display=swap"
rel="stylesheet"
media="print"
onload="this.media='all'"
/>
<noscript>
<link
@ -29,6 +29,7 @@
rel="stylesheet"
/>
</noscript>
<script src="%sveltekit.assets%/js/font-loader.js" defer></script>
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover" class="antialiased">

View File

@ -0,0 +1,7 @@
// Defer loading of fonts to improve performance
window.addEventListener('load', function() {
const fontLink = document.getElementById('google-fonts');
if (fontLink) {
fontLink.media = 'all';
}
});