Replies: 12 comments 5 replies
-
Could it be because of how Page/App routers cache data? as far as I know caching methods differ between this two router system. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
removing this in
here is the difference before and after
|
Beta Was this translation helpful? Give feedback.
-
@Envoy49 How exactly are you testing latency? If testing locally via This is also interesting because technically, A better solution that can work with both App and Pages Router is to use Middleware instead to handle Internationalization, which is supported equally in App and Pages Router. |
Beta Was this translation helpful? Give feedback.
-
I suspect this before. Now it is confirmed. Thanks a lot. |
Beta Was this translation helpful? Give feedback.
-
Confirming that adding the locale configuration object in next.config.js on a blank project immediately pushes the average TTFB from ~10ms to 230+ms. We're using npm, not pnpm. So it's not a pnpm quirk at play. |
Beta Was this translation helpful? Give feedback.
-
I can also confirm the above, as soon as I include i18n in any form/shape I can see the average TTFB going up 10x. Any one looking into this or know if it's nextjs version specific issue? |
Beta Was this translation helpful? Give feedback.
-
This error happens because To fix this, add // next.config.js
module.exports = {
images: {
domains: ['cdn.sanity.io'],
},
};
Then restart your dev server.
This tells Next.js to trust images from Sanity’s CDN. You can read more here: https://nextjs.org/docs/api-reference/next/image#domains
Let me know if you’re still seeing issues after this change! |
Beta Was this translation helpful? Give feedback.
-
Sample here https://codesandbox.io/p/devbox/xvvg2r
Notes: The same experiment locally with i18n Screen.Recording.2025-06-03.at.10.55.16.AM.movwithout i18n Screen.Recording.2025-06-03.at.10.56.53.AM.mov |
Beta Was this translation helpful? Give feedback.
-
You're right — thanks for pointing that out. The external image domain config was unrelated to this specific issue, which is clearly tied to the i18n setup. I checked the sandbox and can confirm the navigation is significantly slower with i18n enabled (around 600ms vs. 300ms without it). This seems to be due to the additional processing Next.js does for locale detection and routing. Potential Solution: // next.config.js Also, for projects that don't need i18n at all, removing the i18n block entirely will improve route transition speeds, especially in dev mode. Let me know if tweaking the config this way improves performance for your case. |
Beta Was this translation helpful? Give feedback.
-
That makes sense — thanks for clarifying. Since disabling locale detection isn't an option, the next step might be to profile where the slowdown is happening exactly. It could be related to how Next.js handles locale-aware routing or how pages are preloaded with different locale contexts. You might try running your app with NODE_ENV=production and enabling Next.js’ trace output or profiling tools like Chrome DevTools or Web Vitals to pinpoint which part of the routing or middleware is adding the extra time. If it turns out to be a limitation in Next.js’ built-in i18n, libraries like next-translate or react-intl might offer more control or better performance in complex setups. Curious to hear what you find — we might be running into similar issues in the future. |
Beta Was this translation helpful? Give feedback.
-
Yeah, the slowdown is happening because when i18n is enabled — especially with automatic locale detection — Next.js adds extra logic during each route change. It checks the user's locale, rewrites the URL if needed, and sometimes loads different data or components based on the locale. That adds processing time, especially in dev mode where everything is less optimized. One possible solution (without removing i18n) is to move locale detection to the edge using middleware, so it only runs once on initial load and not during client-side navigation. That can reduce the impact on every route change. Also worth checking: If your _middleware.js or server functions are locale-aware and slowing things down. Whether you can lazy-load or cache translation files better. If you're open to restructuring, libraries like next-intl or next-translate might give better performance in complex setups by handling i18n more efficiently at runtime. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Link to the code that reproduces this issue
https://codesandbox.io/p/devbox/z3jmlt
To Reproduce
pnpm dev
Current vs. Expected behavior
The combination of App Router with Pages Router seems to introduce large latency.
We migrated some of our page routes to app routes as being suggested by an official Next.JS guide(gradual migration) but this process wasn't smooth and we still couldn't go life due to the latency issues on App Router.
We have done profiling of pages routes vs app routes with the help of load tests and could identify that P95 and P90 latency are 10X higher on App Router compare to Pages Router.
See below screenshot.
I also created a sandbox environment to try and confirm if this behaviour can also be observed there and below on dev server I can see near similar results related to latency.
I got
/test-app-router
in the app folder and/test-pages-router
in pages folder.Results are below:
After caching is stabilised in browser we can clearly see that app router is 3x times slower than pages router.
This behaviour is making gradually migration from pages router to app router impossible.
Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 23.6.0 Available memory (MB): 16384 Available CPU cores: 10 Binaries: Node: 20.11.0 npm: 10.2.4 Yarn: N/A pnpm: 9.6.0 Relevant Packages: next: 14.2.4 // There is a newer version (14.2.7) available, upgrade recommended! eslint-config-next: N/A react: 18.2.0 react-dom: 18.2.0 typescript: 5.2.2
Which area(s) are affected? (Select all that apply)
Not sure
Which stage(s) are affected? (Select all that apply)
next dev (local), next build (local), Other (Deployed)
Additional context
Our production app is running on Linux system.
Same behaviour can be observed both on Linux(prod), Darwin(local) and sandbox environment provided in the link.
Beta Was this translation helpful? Give feedback.
All reactions