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
3468f10c
Unverified
Commit
3468f10c
authored
Mar 23, 2025
by
Lee Robinson
Committed by
GitHub
Mar 23, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
docs: clarify middleware use cases (#77438)
parent
948d59fa
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
12 deletions
+7
-12
14-middleware.mdx
...03-building-your-application/01-routing/14-middleware.mdx
+7
-12
No files found.
docs/01-app/03-building-your-application/01-routing/14-middleware.mdx
View file @
3468f10c
...
@@ -11,21 +11,16 @@ Middleware runs before cached content and routes are matched. See [Matching Path
...
@@ -11,21 +11,16 @@ Middleware runs before cached content and routes are matched. See [Matching Path
## Use Cases
## Use Cases
Integrating
Middleware
into
your
application
can
lead
to
significant
improvements
in
performance
,
security
,
and
user
experience
.
Some
common
scenarios
where
Middleware
is
particularly
effective
include
:
Some
common
scenarios
where
Middleware
is
effective
include
:
-
Authentication
and
Authorization
:
Ensure
user
identity
and
check
session
cookies
before
granting
access
to
specific
pages
or
API
routes
.
-
Quick
redirects
after
reading
parts
of
the
incoming
request
-
Server
-
Side
Redirects
:
Redirect
users
at
the
server
level
based
on
certain
conditions
(
e
.
g
.
,
locale
,
user
role
)
.
-
Rewriting
to
different
pages
based
on
A
/
B
tests
or
experiments
-
Path
Rewriting
:
Support
A
/
B
testing
,
feature
rollouts
,
or
legacy
paths
by
dynamically
rewriting
paths
to
API
routes
or
pages
based
on
request
properties
.
-
Modifying
headers
for
all
pages
or
a
subet
of
pages
-
Bot
Detection
:
Protect
your
resources
by
detecting
and
blocking
bot
traffic
.
-
Logging
and
Analytics
:
Capture
and
analyze
request
data
for
insights
before
processing
by
the
page
or
API
.
-
Feature
Flagging
:
Enable
or
disable
features
dynamically
for
seamless
feature
rollouts
or
testing
.
Recognizing
situations
where
middleware
may
not
be
the
optimal
approach
is
just
as
crucial
.
Here
are
some
scenarios
to
be
mindful
of
:
Middleware
is
_not_
a
good
fit
for
:
-
Complex
Data
Fetching
and
Manipulation
:
Middleware
is
not
designed
for
direct
data
fetching
or
manipulation
,
this
should
be
done
within
Route
Handlers
or
server
-
side
utilities
instead
.
-
Slow
data
fetching
-
Heavy
Computational
Tasks
:
Middleware
should
be
lightweight
and
respond
quickly
or
it
can
cause
delays
in
page
load
.
Heavy
computational
tasks
or
long
-
running
processes
should
be
done
within
dedicated
Route
Handlers
.
-
Session
management
-
Extensive
Session
Management
:
While
Middleware
can
manage
basic
session
tasks
,
extensive
session
management
should
be
managed
by
dedicated
authentication
services
or
within
Route
Handlers
.
-
Direct
Database
Operations
:
Performing
direct
database
operations
within
Middleware
is
not
recommended
.
Database
interactions
should
be
done
within
Route
Handlers
or
server
-
side
utilities
.
## Convention
## Convention
...
...
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