Skip to content

Commit 62cd057

Browse files
authored
tweak preload logic (#395)
* tweak preload logic * fix
1 parent f640931 commit 62cd057

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

apps/svelte.dev/src/hooks.server.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ const mappings = new Map([
1010
['/docs/accessibility-warnings', '/docs/svelte/compiler-warnings']
1111
]);
1212

13+
// selectively preload fonts
14+
const fonts = [
15+
'dm-serif-display-latin-400-normal',
16+
'eb-garamond-latin-400-normal',
17+
'fira-sans-latin-400-normal'
18+
];
19+
1320
/** @type {import('@sveltejs/kit').Handle} */
1421
export async function handle({ event, resolve }) {
1522
// Best effort to redirect from Svelte 4 docs to new docs
@@ -23,12 +30,11 @@ export async function handle({ event, resolve }) {
2330
const response = await resolve(event, {
2431
preload: ({ type, path }) => {
2532
if (type === 'font') {
26-
// only preload header font, everything else is lower priority,
27-
// otherwise it causes congestion that messes up LCP
28-
return path.includes('dm-serif-display-latin-400-normal') && path.endsWith('.woff2');
33+
if (!path.endsWith('.woff2')) return false;
34+
return fonts.some((font) => path.includes(font));
2935
}
3036

31-
return true;
37+
return type === 'js' || type === 'css'; // future-proof, if we add `assets` later
3238
}
3339
});
3440

0 commit comments

Comments
 (0)