Performance issue with next-intl in middleware – all languages being loaded #1953
-
Hi, I wanted to ask about using next-intl in middleware, as I'm encountering a performance issue. My application supports 35 languages, and I noticed that all of them are being loaded in the middleware. This causes the middleware to become overloaded, which significantly affects the initial load time of the application. When I analyze the bundle using next/bundle-analyzer, I can see that all languages are being bundled, as shown in the screenshot below (see attachment). Because of this, the first time a user enters the site, they have to wait quite a while for everything to load. I've noticed this issue some time ago, but I only just identified the root cause today. Do you know:
Any help would be greatly appreciated! Thanks in advance! routing.ts
supported-locales.ts
middleware.ts
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I found the issue – the problem was that I was importing Once I moved that import to the navigation.ts file, the languages were no longer being loaded, and the middleware size dropped to 70kb. |
Beta Was this translation helpful? Give feedback.
I found the issue – the problem was that I was importing
import { createNavigation } from "next-intl/navigation"
in the routing.ts file.
Once I moved that import to the navigation.ts file, the languages were no longer being loaded, and the middleware size dropped to 70kb.