From 416768216b00116a5d37c45279d740de09838d19 Mon Sep 17 00:00:00 2001
From: Berke Güzel <wenekar1@gmail.com>
Date: Mon, 9 Feb 2026 00:07:55 +0300
Subject: font lazy load

---
 src/routes/+layout.svelte | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

(limited to 'src/routes/+layout.svelte')

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>
 
-- 
cgit v1.2.3

