QuiiBz / next-international

Type-safe internationalization (i18n) for Next.js
https://next-international.vercel.app
MIT License
1.26k stars 59 forks source link

[Question] Why some patterns of the middleware matcher are so hard-coded? #201

Closed gustaveWPM closed 11 months ago

gustaveWPM commented 11 months ago

Hello,

From the doc:

export const config = {
  matcher: ['/((?!api|static|.*\\..*|_next|favicon.ico|robots.txt).*)']
}

https://next-international.vercel.app/docs/app-setup#setup-middleware

Why not just:

export const config = {
  matcher: ['/((?!api|static|_next|.*\\..*).*)']
};

I don't understand why the favicon.ico and robots.txt patterns are hard-coded.

It's more of a question than a suggestion. I'm completely hopeless with RegEx: I don't understand anything about it. I'd be curious to know which technical reason makes it better practice to chain hard-coded values.

Is it related to a performance issue, like the fact that a generic RegEx would lead to greater algorithmic complexity? I doubt it very much. So what's the reason?

QuiiBz commented 11 months ago

Sorry, I missed this issue. Next.js recommends to use this pattern in their documentation, so I simply did the same: https://nextjs.org/docs/app/building-your-application/routing/middleware#matcher

I don't think there is any noticeable performance difference between the two solutions. The one in the docs might just be easier to understand, as paths are written directly.