You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Enable dynamic customization of HTTP response codes and headers for individual pages in App Router mode.
Provide developers with finer control over the HTTP responses returned by their Next.js applications, improving flexibility for use cases like SEO optimization, A/B testing, and compliance with security policies.
Non-Goals
This feature request does not aim to modify the underlying HTTP server capabilities such as handling of static files, caching strategies for assets, or server-side streaming capabilities.
It is not intended to introduce changes that would affect the overall performance benchmarks established for Next.js applications under normal operation conditions.
Background
In frameworks like Remix, developers have the ability to manipulate the HTTP responses directly within route loaders using utilities like defer to set HTTP status codes and headers. This functionality is critical for applications that require dynamic response handling based on the request context or specific business logic. Currently, we can only call notFound to set response as 404 status, but if it's 403, 401, etc., there's nothing we can do. Also, we can't set http headers on the page, sometimes we need to set, for example, cache-control to control caching.
My idea is that a new route segement config could be added.
exportconsthandle=async({ params })=>{// fetch data or do thingreturn{status: 404,// custom status codeheaders: {// custom headers"Cache-Control": "no-store",}}}
or, provide a util function only for the server side.
exportdefaultasyncfunctionPage(){response({status: 404,// custom status codeheaders: {// custom headers"Cache-Control": "no-store",}})/// }
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Goals
Non-Goals
This feature request does not aim to modify the underlying HTTP server capabilities such as handling of static files, caching strategies for assets, or server-side streaming capabilities.
It is not intended to introduce changes that would affect the overall performance benchmarks established for Next.js applications under normal operation conditions.
Background
In frameworks like Remix, developers have the ability to manipulate the HTTP responses directly within route loaders using utilities like defer to set HTTP status codes and headers. This functionality is critical for applications that require dynamic response handling based on the request context or specific business logic. Currently, we can only call
notFound
to set response as 404 status, but if it's 403, 401, etc., there's nothing we can do. Also, we can't set http headers on the page, sometimes we need to set, for example,cache-control
to control caching.Example in remix:
Proposal
My idea is that a new route segement config could be added.
or, provide a util function only for the server side.
Beta Was this translation helpful? Give feedback.
All reactions