𝗛𝗼𝘄 𝗪𝗲 𝗖𝘂𝘁 𝗦𝗹𝗼𝘄 𝗥𝗲𝘀𝗽𝗼𝗻𝘀𝗲𝘀 𝗯𝘆 𝟴𝟬%
Subito is a top marketplace in Italy. We handle thousands of requests every minute. Our ad detail page is vital for SEO and revenue.
We moved this page from Next.js Pages Router to App Router. We did not stop product work to do this. We moved in small steps.
Here is how we did it.
𝗧𝗵𝗲 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵
We used an incremental strategy. We added the App Router tree alongside the old Pages Router. This let us ship new features while we migrated.
We used Server Components to own data fetching. This removed the need to pass data through many layers. We also created a Data Access Layer. This made sure we only fetch data once per request.
We used Suspense and the use() hook to enable HTML streaming. This shows a skeleton screen while data loads. The user sees the page faster.
𝗧𝗵𝗲 𝗖𝗵𝗮𝗹𝗹𝗲𝗻𝗴𝗲𝘀
Problem 1: HTTP 410 Gone Search engines need a 410 status when a page is permanently removed. The App Router does not have a built-in way to send this. We solved this using our Express server. The server intercepts the response and changes the status code.
Problem 2: HTML Streaming We found that our loading skeletons did not appear. The page stayed blank for seconds.
We discovered that Nginx and Akamai were buffering our responses. If the CDN buffers the HTML, streaming fails. We had to turn off buffering in Nginx and apply custom settings in Akamai. Once we fixed this, content streamed to the user perfectly.
𝗧𝗵𝗲 𝗥𝗼𝗹𝗹𝗼𝘂𝘁
We rolled out in two phases to protect our SEO.
Phase 1: We moved traffic to the App Router but kept streaming off. We did this one category at a time.
Phase 2: We enabled HTML streaming. We tested this on small categories first. Our SEO team monitored rankings for two weeks before we moved to the next category.
𝗧𝗵𝗲 𝗥𝗲𝘀𝘂𝗹𝘁𝘀
The results were huge. Before the migration, up to 40% of our responses were slow. After the migration, slow responses dropped by 80%.
Most pages now load in under 500ms.
𝗧𝗮𝗸𝗲𝗮𝘄𝗮𝘆𝘀
- Use parallel routing to migrate without stopping feature work.
- A custom server layer helps you control traffic and fix framework gaps.
- Streaming requires configuration at every layer. Check Nginx and your CDN.
- Test your SEO metrics during the rollout.
איך צמצמנו תגובות איטיות ב-80% באמצעות מעבר ל-Next.js App Router
במסע שלנו עם Next.js, אחת הבעיות המשמעותיות ביותר שעמדו בפנינו הייתה זמן התגובה (response time) של האפליקציה שלנו. תגובות איטיות פגעו בחוויית המשתמש וביכולת שלנו לשמור על משתמשים מעורבים.
האתגר: מגבלות ה-Pages Router
בשימוש ב-Pages Router, כל דף היה דורש שליפת נתונים בשרת, אך לאחר מכן, כל ה-JavaScript הנדרש להרצת הדף היה נשלח לצד הלקוח. תהליך ה-Hydration היה כבד, מה שהוביל לזמני טעינה ארוכים ולחוויית משתמש פחות חלקה, במיוחד במכשירים חלשים או בתנאי רשת איטיים.
הפתרון: המעבר ל-App Router
החלטנו לבצע מיגרציה ל-App Router של Next.js, והשינוי הזה לא היה רק שינוי של מבנה התיקיות, אלא שינוי פרדיגמה באופן שבו אנחנו מנהלים נתונים ורכיבים.
React Server Components (RSC)
היתרון המשמעותי ביותר שקיבלנו הוא היכולת להשתמש ב-Server Components. בניגוד לרכיבים רגילים, Server Components מורצים אך ורק בשרת. זה אומר ש:
- צמצום ה-JavaScript: כמות ה-JavaScript שנשלחת לדפדפן קטנה משמעותית, מכיוון שהלוגיקה של הרכיב נשארת בשרת.
- שליפת נתונים יעילה: שליפת הנתונים מתבצעת קרוב יותר למקור הנתונים (בשרת), מה שמפחית את השיהוי (latency) שנוצר בתקשורת בין הלקוח לשרת.
- Bundle Size קטן יותר: ה-Bundle size של הלקוח קטן יותר, מה שמאפשר טעינה מהירה יותר של הדף.
Streaming ו-Suspense
עוד כלי עוצמתי ב-App Router הוא ה-Streaming. בעזרת Suspense, יכולנו לפצל את הרינדור של הדף. במקום לחכות שכל הנתונים יגיעו לפני שהדף יוצג, אנחנו יכולים לשלוח את החלקים הסטטיים של הדף מיד, ולהציג "שלדי טעינה" (skeletons) עבור החלקים שדורשים שליפת נתונים ארוכה. זה שיפר דרמטית את ה-Perceived Performance (ביצועים נתפסים) של המשתמשים שלנו.
התוצאות
המעבר ל-App Router הביא לשיפורים מיידיים ומדידים:
- ירידה של 80% בתגובות האיטיות.
- שיפור משמעותי ב-TTFB (Time to First Byte).
- חוויית משתמש חלקה ומהירה יותר.
המיגרציה לא הייתה קלה ודרשה למידה מחדש של חלק מהתהליכים, אך התוצאות הוכחו כמשתלמות ביותר עבור הביצועים של האפליקציה שלנו.