Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
f8ba588c
Unverified
Commit
f8ba588c
authored
Dec 27, 2023
by
Jordy van den Aardweg
Committed by
GitHub
Dec 27, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
docs: Update Middleware docs on ignoring prefetches (#56799)
Co-authored-by:
Lee Robinson
<
me@leerob.io
>
parent
7e00d187
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
0 deletions
+23
-0
11-middleware.mdx
...01-building-your-application/01-routing/11-middleware.mdx
+23
-0
No files found.
docs/02-app/01-building-your-application/01-routing/11-middleware.mdx
View file @
f8ba588c
...
...
@@ -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.
Configured matchers:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment