-
Hi! I'm starting a new project with Next.js and Vercel. At first, I set all pages with ISR, but most of this usage now comes from the middleware. I’m trying to remove this middleware somehow, since it’s only being used for this library. Honestly, the only useful part for me is the language detection on the home page. ![]() While trying this, I ran into another issue: Related discussions: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hmm, that looks a bit odd indeed. Can you share how many middleware invocations you have? Based on my local tests with the App Router example, the middleware invocation takes a few ms (typically between 4-8ms). Let's say we take 8ms as an example and 2h 1m of compute time, that would account for 907,500 invocations! Is your middleware potentially called on unrelated routes? One thing to be aware of is that Next.js prefetches pages for all links on a page. So if you render a page and it has links to 100 pages, then you don't get 1 middleware invocation per "visit", but 101. To address your question from above, |
Beta Was this translation helpful? Give feedback.
Hmm, that looks a bit odd indeed. Can you share how many middleware invocations you have?
Based on my local tests with the App Router example, the middleware invocation takes a few ms (typically between 4-8ms).
Let's say we take 8ms as an example and 2h 1m of compute time, that would account for 907,500 invocations!
Is your middleware potentially called on unrelated routes? One thing to be aware of is that Next.js prefetches pages for all links on a page. So if you render a page and it has links to 100 pages, then you don't get 1 middleware invocation per "visit", but 101.
To address your question from above,
localePrefix: 'as-needed'
indeed requires middleware invocations—at least for yo…