𝗛𝗼𝘄 𝗪𝗲 𝗖𝘂𝘁 𝗦𝗹𝗼𝘄 𝗥𝗲𝘀𝗽𝗼𝗻𝘀𝗲𝘀 𝗯𝘆 𝟴𝟬%

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.

𝗧𝗮𝗸𝗲𝗮𝘄𝗮𝘆𝘀

Next.js App Router માં સ્થળાંતર કરીને અમે ધીમા પ્રતિસાદ (slow responses) ને 80% કેવી રીતે ઘટાડ્યા

અમારા પ્લેટફોર્મ પર, વપરાશકર્તા અનુભવ (user experience) એ અમારી પ્રાથમિકતા છે. જો પેજ લોડ થવામાં વિલંબ થાય, તો વપરાશકર્તાઓ પ્લેટફોર્મ છોડી દે છે. તાજેતરમાં, અમે નોંધ્યું કે અમારા અમુક પેજ પર પ્રતિસાદનો સમય (response time) ઘણો વધારે હતો. આ લેખમાં, અમે વિગતવાર જણાવીશું કે કેવી રીતે Next.js App Router પર સ્થળાંતર કરીને અમે ધીમા પ્રતિસાદને 80% સુધી ઘટાડી શક્યા.

સમસ્યા: Pages Router ની મર્યાદાઓ

અગાઉ, અમે Next.js ના Pages Router નો ઉપયોગ કરી રહ્યા હતા. જેમ જેમ અમારું એપ્લિકેશન મોટું થતું ગયું, તેમ તેમ અમને નીચેની સમસ્યાઓનો સામનો કરવો પડ્યો:

ઉકેલ: Next.js App Router અને React Server Components (RSC)

અમે નક્કી કર્યું કે App Router પર સ્થળાંતર કરવું એ જ શ્રેષ્ઠ રસ્તો છે. અહીં તેના મુખ્ય કારણો છે:

1. React Server Components (RSC) નો ઉપયોગ

App Router માં, ઘટકો (components) ડિફોલ્ટ રીતે Server Components હોય છે. આનો અર્થ એ છે કે:

2. Streaming અને Suspense

અગાઉ, આખું પેજ રેન્ડર થાય ત્યાં સુધી યુઝર રાહ જોતો હતો. App Router માં, અમે Suspense નો ઉપયોગ કરીને 'Streaming' શરૂ કરી. આનાથી:

3. બહેતર Caching અને Data Fetching

App Router માં fetch API ને એક્સટેન્ડ કરવામાં આવ્યું છે, જે સર્વર-સાઇડ કેશિંગને વધુ સરળ બનાવે છે. આનાથી ડેટાબેઝ પરનો લોડ ઘટ્યો અને પ્રતિસાદનો સમય પણ ઝડપી બન્યો.

પરિણામો

સ્થળાંતર પછી, અમે નીચે મુજબના સુધારા જોયા:

નિષ્કર્ષ

Next.js App Router પર સ્થળાંતર કરવું એ માત્ર એક ટેકનિકલ અપડેટ નહોતું, પરંતુ અમારા વપરાશકર્તા અનુભવને સુધારવા માટેનું એક વ્યૂહાત્મક પગલું હતું. જો તમે પણ મોટા JavaScript બંડલ અને ધીમી લોડિંગ સ્પીડથી પરેશાન હોવ, તો App Router પર સ્થળાંતર કરવાનું વિચારવું જોઈએ.