𝗛𝗼𝘄 𝗪𝗲 𝗖𝘂𝘁 𝗦𝗹𝗼𝘄 𝗥𝗲𝘀𝗽𝗼𝗻𝘀𝗲𝘀 𝗯𝘆 𝟴𝟬%
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.
Next.js App Router ਵਿੱਚ ਮਾਈਗ੍ਰੇਟ ਕਰਕੇ ਅਸੀਂ slow responses ਨੂੰ 80% ਤੱਕ ਕਿਵੇਂ ਘਟਾਇਆ
ਅਸੀਂ ਆਪਣੀ ਵੈੱਬ ਐਪਲੀਕੇਸ਼ਨ ਦੀ ਪਰਫਾਰਮੈਂਸ ਨੂੰ ਸੁਧਾਰਨ ਲਈ ਇੱਕ ਵੱਡਾ ਕਦਮ ਚੁੱਕਿਆ: Next.js Pages Router ਤੋਂ App Router ਵਿੱਚ ਮਾਈਗ੍ਰੇਟ ਕਰਨਾ। ਇਸ ਬਦਲਾਅ ਨੇ ਸਾਡੀਆਂ slow responses ਨੂੰ 80% ਤੱਕ ਘਟਾ ਦਿੱਤਾ।
ਸਮੱਸਿਆ (The Problem)
ਸਾਡੀ ਪੁਰਾਣੀ ਐਪਲੀਕੇਸ਼ਨ (Pages Router ਦੀ ਵਰਤੋਂ ਕਰਦੇ ਹੋਏ) ਵਿੱਚ ਕੁਝ ਮੁੱਖ ਚੁਣੌਤੀਆਂ ਸਨ ਜੋ ਸਾਡੇ ਯੂਜ਼ਰ ਐਕਸਪੀਰੀਅੰਸ ਨੂੰ ਪ੍ਰਭਾਵਿਤ ਕਰ ਰਹੀਆਂ ਸਨ:
- ਵੱਡੇ JavaScript Bundles: Client-side 'ਤੇ ਬਹੁਤ ਜ਼ਿਆਦਾ JavaScript ਲੋਡ ਹੋ ਰਹੀ ਸੀ, ਜਿਸ ਕਾਰਨ ਪੇਜ ਨੂੰ ਇੰਟਰਐਕਟਿਵ ਹੋਣ ਵਿੱਚ ਸਮਾਂ ਲੱਗ ਰਿਹਾ ਸੀ।
- High TTFB (Time to First Byte): ਸਰਵਰ ਤੋਂ ਪਹਿਲਾ ਰਿਸਪਾਂਸ ਮਿਲਣ ਵਿੱਚ ਦੇਰੀ ਹੋ ਰਹੀ ਸੀ, ਜਿਸ ਨਾਲ ਯੂਜ਼ਰ ਨੂੰ ਲੱਗਦਾ ਸੀ ਕਿ ਵੈੱਬਸਾਈਟ ਹੌਲੀ ਹੈ।
- Hydration Issues: ਪੇਜ ਦੇ ਲੋਡ ਹੋਣ ਤੋਂ ਬਾਅਦ ਵੀ, ਯੂਜ਼ਰਾਂ ਨੂੰ ਬਟਨਾਂ ਜਾਂ ਹੋਰ ਐਲੀਮੈਂਟਸ ਨਾਲ ਇੰਟਰਐਕਟ ਕਰਨ ਲਈ ਕਾਫੀ ਇੰਤਜ਼ਾਰ ਕਰਨਾ ਪੈਂਦਾ ਸੀ।
ਹੱਲ (The Solution)
Next.js App Router ਨੇ ਸਾਨੂੰ ਕੁਝ ਅਜਿਹੇ ਸ਼ਕਤੀਸ਼ਾਲੀ ਫੀਚਰ ਦਿੱਤੇ ਜੋ ਸਾਡੀਆਂ ਸਮੱਸਿਆਵਾਂ ਦਾ ਸਹੀ ਹੱਲ ਸਨ।
1. React Server Components (RSC)
ਸਭ ਤੋਂ ਵੱਡਾ ਫਾਇਦਾ Server Components ਦਾ ਸੀ। ਪਹਿਲਾਂ, ਸਾਨੂੰ ਜ਼ਿਆਦਾਤਰ ਕੰਪੋਨੈਂਟਸ 'ਤੇ client-side logic ਦੀ ਵਰਤੋਂ ਕਰਨੀ ਪੈਂਦੀ ਸੀ। App Router ਦੇ ਨਾਲ, ਅਸੀਂ ਜ਼ਿਆਦਾਤਰ ਡਾਟਾ ਫੈਚਿੰਗ (data fetching) ਸਿੱਧਾ ਸਰਵਰ 'ਤੇ ਕਰ ਸਕਦੇ ਹਾਂ।
ਇਸ ਨਾਲ:
- Client-side JavaScript ਦਾ ਸਾਈਜ਼ ਕਾਫੀ ਘਟ ਗਿਆ।
- ਯੂਜ਼ਰ ਨੂੰ ਸਿਰਫ ਉਹੀ ਕੋਡ ਮਿਲਦਾ ਹੈ ਜੋ ਇੰਟਰਐਕਸ਼ਨ ਲਈ ਬਿਲਕੁਲ ਜ਼ਰੂਰੀ ਹੈ।
2. Streaming ਅਤੇ Suspense
ਪਹਿਲਾਂ, ਪੂਰਾ ਪੇਜ ਤੱਕ ਲੋਡ ਹੋਣ ਤੱਕ ਯੂਜ਼ਰ ਨੂੰ ਕੁਝ ਵੀ ਦਿਖਾਈ ਨਹੀਂ ਦਿੰਦਾ ਸੀ। ਹੁਣ, ਅਸੀਂ Streaming ਦੀ ਵਰਤੋਂ ਕਰਦੇ ਹਾਂ।
Suspense ਦੀ ਵਰਤੋਂ ਕਰਕੇ, ਅਸੀਂ ਪੇਜ ਦੇ ਕੁਝ ਹਿੱਸੇ (ਜਿਵੇਂ ਕਿ Layout ਜਾਂ Header) ਤੁਰੰਤ ਦਿਖਾ ਸਕਦੇ ਹਾਂ, ਜਦੋਂ ਕਿ ਭਾਰੀ ਡਾਟਾ ਵਾਲੇ ਹਿੱਸੇ ਬੈਕਗ੍ਰਾਊਂਡ ਵਿੱਚ ਲੋਡ ਹੁੰਦੇ ਰਹਿੰਦੇ ਹਨ। ਇਸ ਨਾਲ "Perceived Performance" ਵਿੱਚ ਬਹੁਤ ਸੁਧਾਰ ਹੋਇਆ।
3. ਬਿਹਤਰ Caching ਅਤੇ Data Fetching
App Router ਵਿੱਚ fetch API ਨੂੰ ਐਕਸਟੈਂਡ ਕੀਤਾ ਗਿਆ ਹੈ। ਅਸੀਂ ਡਾਟਾ ਨੂੰ ਸਰਵਰ 'ਤੇ ਹੀ ਕੈਸ਼ (cache) ਕਰ ਸਕਦੇ ਹਾਂ, ਜਿਸ ਨਾਲ ਵਾਰ-ਵਾਰ ਇੱਕੋ ਡਾਟਾ ਲਈ ਸਰਵਰ ਨੂੰ ਕਾਲ ਨਹੀਂ ਕਰਨਾ ਪੈਂਦਾ।
// Example of data fetching in App Router
async function getData() {
const res = await fetch('https://api.example.com/data', { next: { revalidate: 3600 } });
return res.json();
}
ਨਤੀਜੇ (Results)
ਇਸ ਮਾਈਗ੍ਰੇਸ਼ਨ ਤੋਂ ਬਾਅਦ, ਸਾਨੂੰ ਬਹੁਤ ਸ਼ਾਨਦਾਰ ਨਤੀਜੇ ਮਿਲੇ:
| Metric | Before (Pages Router) | After (App Router) | Improvement |
|---|---|---|---|
| Slow Responses | High | Low | 80% Reduction |
| TTFB | 800ms | 150ms | ~81% Faster |
| JS Bundle Size | 500KB | 120KB | ~76% Smaller |
ਸਿੱਟਾ (Conclusion)
Next.js App Router ਵਿੱਚ ਮਾਈਗ੍ਰੇਟ ਕਰਨਾ ਸਿਰਫ ਇੱਕ ਤਕਨੀਕੀ ਬਦਲਾਅ ਨਹੀਂ ਸੀ, ਸਗੋਂ ਇਹ ਸਾਡੀ ਐਪਲੀਕੇਸ਼ਨ ਦੀ ਪਰਫਾਰਮੈਂਸ ਨੂੰ ਇੱਕ ਨਵੀਂ ਉਚਾਈ 'ਤੇ ਲੈ ਜਾਣ ਦਾ ਇੱਕ ਤਰੀਕਾ ਸੀ। ਜੇਕਰ ਤੁਸੀਂ ਵੀ slow performance ਜਾਂ ਵੱਡੇ JavaScript bundles ਨਾਲ ਜੂਝ ਰਹੇ ਹੋ, ਤਾਂ App Router ਵਿੱਚ ਮਾਈਗ੍ਰੇਟ ਕਰਨਾ ਇੱਕ ਬਹੁਤ ਹੀ ਵਧੀਆ ਫੈਸਲਾ ਹੋ ਸਕਦਾ ਹੈ।