Unverified Commit f8ba588c authored by Jordy van den Aardweg's avatar Jordy van den Aardweg Committed by GitHub

docs: Update Middleware docs on ignoring prefetches (#56799)

Co-authored-by: 's avatarLee Robinson <me@leerob.io>
parent 7e00d187
...@@ -97,6 +97,29 @@ export const config = { ...@@ -97,6 +97,29 @@ export const config = {
} }
``` ```
You can also ignore prefetches (from `next/link`) that don't need to go through the Middleware using the `missing` array:
```js filename="middleware.js"
export const config = {
matcher: [
/*
* Match all request paths except for the ones starting with:
* - api (API routes)
* - _next/static (static files)
* - _next/image (image optimization files)
* - favicon.ico (favicon file)
*/
{
source: '/((?!api|_next/static|_next/image|favicon.ico).*)',
missing: [
{ type: 'header', key: 'next-router-prefetch' },
{ type: 'header', key: 'purpose', value: 'prefetch' },
],
},
],
}
```
> **Good to know**: The `matcher` values need to be constants so they can be statically analyzed at build-time. Dynamic values such as variables will be ignored. > **Good to know**: The `matcher` values need to be constants so they can be statically analyzed at build-time. Dynamic values such as variables will be ignored.
Configured matchers: Configured matchers:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment