From 9a81e63740241987dac62b0c3a9f6f9b5199a6b5 Mon Sep 17 00:00:00 2001 From: sebastjanartic <45803536-sebastjanartic@users.noreply.replit.com> Date: Thu, 5 Mar 2026 14:36:42 +0000 Subject: [PATCH] Improve page loading performance by deferring off-screen content Implement lazy loading for lower sections of the homepage to optimize initial render and improve user experience. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 1f7e7e89-a520-4970-9645-37daadc466dc Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: 97dab47f-9107-41f0-9b7a-5900b3b486e6 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/f209e72a-0939-48fa-84fc-57854de71967/1f7e7e89-a520-4970-9645-37daadc466dc/ZApZ5Qi Replit-Helium-Checkpoint-Created: true --- client/src/pages/home.tsx | 97 ++++++++++++++++++++++++++------------- 1 file changed, 65 insertions(+), 32 deletions(-) diff --git a/client/src/pages/home.tsx b/client/src/pages/home.tsx index 7c83e33..313b74c 100644 --- a/client/src/pages/home.tsx +++ b/client/src/pages/home.tsx @@ -15,7 +15,7 @@ import { RecipeWidget } from "@/components/recipe-widget"; import { NewsWidget } from "@/components/news-widget"; import { SidebarWeatherWidget } from "@/components/weather-widget"; import { BreakingNewsWidget } from "@/components/breaking-news-widget"; -import { useState, useEffect, useCallback, useRef, useMemo } from "react"; +import { useState, useEffect, useCallback, useRef, useMemo, lazy, Suspense } from "react"; function useFocalPoints() { const { data } = useQuery>({ @@ -466,6 +466,33 @@ function FeaturedCarousel({ articles, popular, galleryImages, focalPoints }: { a ); } +function LazySection({ children, minHeight = "200px" }: { children: JSX.Element; minHeight?: string }) { + const ref = useRef(null); + const [visible, setVisible] = useState(false); + + useEffect(() => { + const el = ref.current; + if (!el) return; + const obs = new IntersectionObserver( + ([entry]) => { + if (entry.isIntersecting) { + setVisible(true); + obs.disconnect(); + } + }, + { rootMargin: "300px" } + ); + obs.observe(el); + return () => obs.disconnect(); + }, []); + + return ( +
+ {visible ? children : null} +
+ ); +} + function BentoSkeleton() { return (
@@ -663,41 +690,47 @@ export default function Home() {
{gridRows.map((row, ri) => ( -
-
- {row.map((item) => - item.type === "widget" - ?
{item.widget!.el}
- : item.type === "ad" - ?
- : item.article - ? - : null - )} - {ri === gridRows.length - 1 && widePickedArticles.length > 0 && ( -
- - {widePickedArticles[1] && } -
- )} + +
+
+ {row.map((item) => + item.type === "widget" + ?
{item.widget!.el}
+ : item.type === "ad" + ?
+ : item.article + ? + : null + )} + {ri === gridRows.length - 1 && widePickedArticles.length > 0 && ( +
+ + {widePickedArticles[1] && } +
+ )} +
-
+ ))} -
- {bottomSection.map((item, i) => ( -
- {item.el} -
- ))} -
+ +
+ {bottomSection.map((item, i) => ( +
+ {item.el} +
+ ))} +
+
-
- - - -
-
+ +
+ + + +
+
+