Browse Source

perf: optimize images and add ISR caching

- Add ISR revalidate=3600 to homepage (avoid re-fetching Firebase URLs)
- Enable AVIF/WebP image formats in next.config.js
- Add priority + sizes to avatar image for faster LCP
- Lower quality to 60 on project card images (visible at small sizes)
- Add sizes hints to all images for correct srcset selection
- Lazy-load non-top card stack images

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
rriecc 9 months ago
parent
commit
2a29b2e363

+ 3 - 0
app/page.tsx

@@ -4,6 +4,9 @@ import Loading from "@/components/loading";
 import HomeClient from "@/components/home-client";
 import { getHomeData } from "@/lib/data";
 
+// Cache the page for 1 hour — avoids re-fetching Firebase URLs on every request
+export const revalidate = 3600;
+
 async function HomeContent() {
   const data = await getHomeData();
 

+ 2 - 0
components/actions.tsx

@@ -15,6 +15,8 @@ const Actions = ({ photoUrl }: ActionsProps) => {
           alt="SecondSelf - AI Agent Social Network"
           className="w-full h-full rounded-2xl object-contain"
           height={1280}
+          quality={60}
+          sizes="(max-width: 768px) 300px, 500px"
           src={photoUrl}
           width={2259}
         />

+ 2 - 0
components/avatar.tsx

@@ -55,10 +55,12 @@ const AvatarTransition: React.FC<AvatarTransitionProps> = ({
           variants={avatarVariants}
         >
           <BlurImage
+            priority
             alt="Avatar"
             className="w-24 h-24 md:w-28 md:h-28 object-cover mb-4 border-2 border-transparent dark:border-knight rounded-full"
             containerClassName="rounded-full"
             height={128}
+            sizes="(max-width: 768px) 96px, 112px"
             src={avatarUrl}
             width={128}
           />

+ 3 - 1
components/card-stack.tsx

@@ -73,7 +73,9 @@ const CardStack: React.FC<CardStackProps> = ({ photos }) => {
             className="object-cover w-[80%] mx-auto md:w-full rounded-2xl aspect-video"
             containerClassName="rounded-2xl"
             height={200}
-            quality={80}
+            loading={index === cards.length - 1 ? "eager" : "lazy"}
+            quality={60}
+            sizes="(max-width: 768px) 200px, 355px"
             src={card.imageUrl}
             width={355}
           />

+ 2 - 1
components/chatbot.tsx

@@ -15,7 +15,8 @@ const Chatbot = ({ chatbotUrl }: ChatbotProps) => {
           alt="Chatbot"
           className="h-48 md:h-96 object-cover rounded-2xl"
           height={1280}
-          quality={75}
+          quality={60}
+          sizes="(max-width: 768px) 400px, 800px"
           src={chatbotUrl}
           width={2629}
         />

+ 2 - 1
components/paper.tsx

@@ -14,7 +14,8 @@ const Paper = ({ paperUrl }: PaperProps) => {
           alt="Paper"
           className="h-full w-full rounded-2xl object-contain"
           height={1280}
-          quality={75}
+          quality={60}
+          sizes="(max-width: 768px) 300px, 500px"
           src={paperUrl}
           width={1577}
         />

+ 2 - 3
components/webagent.tsx

@@ -13,12 +13,11 @@ const WebAgent = ({ webAgentUrl }: WebAgentProps) => {
 
       <div className="absolute top-1/2 -translate-y-1/2 left-24 md:left-32 transform -rotate-[30deg] rounded-2xl w-[80%]">
         <Image
-          priority
           alt="Web Agent Interface Preview"
           className="w-full h-full object-contain rounded-2xl"
           height={800}
-          loading="eager"
-          quality={75}
+          quality={60}
+          sizes="(max-width: 768px) 300px, 500px"
           src={webAgentUrl}
           width={1000}
         />

+ 1 - 0
next.config.js

@@ -4,6 +4,7 @@ const nextConfig = {
     viewTransition: true,
   },
   images: {
+    formats: ["image/avif", "image/webp"],
     remotePatterns: [
       {
         protocol: "https",