diff options
| author | Berke Güzel <wenekar1@gmail.com> | 2026-02-09 00:07:55 +0300 |
|---|---|---|
| committer | Berke Güzel <wenekar1@gmail.com> | 2026-02-09 00:07:55 +0300 |
| commit | 416768216b00116a5d37c45279d740de09838d19 (patch) | |
| tree | 3f657ecf052f5ad5862669f68151ef8403ab2134 /src/routes | |
| parent | 22986c36fe3ed7ad3fe585b1da608c2e5fb2a54d (diff) | |
font lazy load
Diffstat (limited to 'src/routes')
| -rw-r--r-- | src/routes/+layout.svelte | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 5229cac..9b488bd 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -8,6 +8,17 @@ let { children } = $props(); onMount(() => { + const loadFonts = () => { + if (document.querySelector('link[data-app-fonts="true"]')) return; + + const link = document.createElement("link"); + link.rel = "stylesheet"; + link.href = + "https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap"; + link.setAttribute("data-app-fonts", "true"); + document.head.appendChild(link); + }; + const loadAnalytics = () => { if (document.querySelector('script[data-goatcounter-script="true"]')) return; @@ -21,13 +32,18 @@ document.head.appendChild(script); }; + const runDeferredLoads = () => { + loadFonts(); + loadAnalytics(); + }; + if (document.readyState === "complete") { - window.setTimeout(loadAnalytics, 0); + window.setTimeout(runDeferredLoads, 0); return; } - window.addEventListener("load", loadAnalytics, { once: true }); - return () => window.removeEventListener("load", loadAnalytics); + window.addEventListener("load", runDeferredLoads, { once: true }); + return () => window.removeEventListener("load", runDeferredLoads); }); </script> |
