Production settings#
This page lists recommended NEXT_FRAMEWORK values for production.
Each entry explains why the production value differs from the development default.
For the full list of available keys, their defaults, and their semantics, see Settings.
Each snippet below sets one key on an existing NEXT_FRAMEWORK dict.
Declare NEXT_FRAMEWORK = {} once before the first override, or merge the keys into a single literal as shown under Combining keys.
Keys left unset keep their framework default because the framework merges Settings defaults under the user dict.
Strict context#
NEXT_FRAMEWORK = {}
NEXT_FRAMEWORK["STRICT_CONTEXT"] = True
Use STRICT_CONTEXT: True in production so a misconfigured context processor fails loudly.
See Settings for behaviour and exception types.
Strict loading#
NEXT_FRAMEWORK["STRICT_LOADING"] = True
Use STRICT_LOADING: True in production so a page.py that fails to import or a {% component %} name that does not resolve fails the request instead of serving a silently degraded page.
With DEBUG=False the client sees the generic 500 page, and the traceback appears only in the server log through logger.exception.
Without the flag a broken page.py answers a generic 404 and a missed component renders as an empty string, which monitoring rarely catches.
See Settings for the loudness table across DEBUG and the strict flags.
Eager component loading#
NEXT_FRAMEWORK["LAZY_COMPONENT_MODULES"] = False
LAZY_COMPONENT_MODULES: False is the default, and production confirms it.
The framework discovers the component tree eagerly in both modes, so the registry knows every component name before traffic.
The flag controls only when each component.py module is imported.
With the default False, every component.py is imported during startup, so any import-time error surfaces before the first request.
With True, a component.py is imported on the first render that resolves the component rather than during startup.
See Settings and Testing for lazy behaviour and testing helpers.
Static backend#
NEXT_FRAMEWORK["STATIC_BACKENDS"] = [
{"BACKEND": "notes.backends.CdnBackend", "OPTIONS": {}},
]
Point at a CDN aware backend in production.
The default StaticFilesBackend is appropriate for single host deployments where the same process serves both HTML and static files.
JS context serializer#
NEXT_FRAMEWORK["JS_CONTEXT_SERIALIZER"] = "next.static.PydanticJsContextSerializer"
Set the serializer when context values include types beyond the standard JSON set.
PydanticJsContextSerializer handles Pydantic models and falls back to the Django JSON encoder for plain values.
Note
PydanticJsContextSerializer requires the pydantic package, which is not a dependency of next.dj.
Install it separately (pip install pydantic) before enabling this serializer.
If pydantic is not installed, the first render that serializes context raises ImportError.
Page backends with context processors#
from next.conf import extend_default_backend
NEXT_FRAMEWORK["PAGE_BACKENDS"] = extend_default_backend(
"PAGE_BACKENDS",
OPTIONS={"context_processors": [
"notes.context_processors.csp_nonce",
"notes.context_processors.tenant",
]},
)
Use extend_default_backend to patch the default page backend entry with production context processors.
The OPTIONS dict is merged, so the other default keys survive.
Form action backend#
NEXT_FRAMEWORK["FORM_ACTION_BACKENDS"] = [
{"BACKEND": "notes.backends.RateLimitedFormActionBackend"},
]
Register a custom backend that subclasses RegistryFormActionBackend and rate limits dispatch for endpoints exposed to anonymous users.
See Write a form action backend.
Combining keys#
When several recommendations apply at once, merge them into a single NEXT_FRAMEWORK literal.
from next.conf import extend_default_backend
NEXT_FRAMEWORK = {
"STRICT_CONTEXT": True,
"STRICT_LOADING": True,
"LAZY_COMPONENT_MODULES": False,
"STATIC_BACKENDS": [
{"BACKEND": "notes.backends.CdnBackend", "OPTIONS": {}},
],
"JS_CONTEXT_SERIALIZER": "next.static.PydanticJsContextSerializer",
"PAGE_BACKENDS": extend_default_backend(
"PAGE_BACKENDS",
OPTIONS={"context_processors": [
"notes.context_processors.csp_nonce",
"notes.context_processors.tenant",
]},
),
"FORM_ACTION_BACKENDS": [
{"BACKEND": "notes.backends.RateLimitedFormActionBackend"},
],
}
Keep only the keys the deployment changes. The framework supplies the default for every key left out, so there is no need to duplicate the full default structures documented on Settings.
Runtime script overrides#
Strict content security policies sometimes need nonces or manual ordering for the bundled next.min.js shell.
NEXT_FRAMEWORK["NEXT_JS_OPTIONS"] accepts template overrides and ScriptInjectionPolicy values described on Settings and in JavaScript context.
See also#
See also
Deployment checklist for the full pre-flight list. Settings for every available key.