Too many "The number of times your Edge Middleware received a request."

I am using the next-intl Internationalization library for my multi-language project. And I configure the middleware.js in the root like this below:

import createMiddleware from 'next-intl/middleware';
import { localePrefix, locales } from '../navigation';

export default createMiddleware({
  locales,
  localePrefix,
  defaultLocale: 'en'
});

export const config = {
    matcher: [
        '/((?!api|_next/static|_next/image|favicon.ico|ads.txt|robots.txt|download|images|logo).*)',
      ]
};

And now there is an Edge Middleware request for every single page request, which cause high volume of the Edge Middleware Invocation

Is this normal or any issue in the middleware configuration? I just want to confirm if the internationalization will cost the Edge Middleware Invocation or not.

Thanks a lot!

Hi, @stevensk-king! Thanks for your patience :pray:

Yes, it’s normal for the next-intl middleware to invoke Edge Middleware for every page request that matches the configured matcher. This behaviour is expected and is how the internationalization middleware works to handle language routing and preferences.

To optimize your setup, you could do the following:

  1. Refining your matcher: Make sure you’re only invoking the middleware where necessary. Your current configuration looks good, but you might want to review if there are any other paths that could be excluded.
  2. Caching strategies: Implement caching strategies where possible to reduce the number of dynamic page generations. This can help in minimizing the load on the Edge Middleware by serving cached responses for repeated requests.
  3. Monitoring and analysis: Keep an eye on your Edge Middleware Invocations and correlate them with your traffic. This will help you understand if the invocations are proportional to your site’s usage.

Let us know how you get on!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.