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.
Reference for behaviour and exception types: Settings.
Eager Component Loading¶
NEXT_FRAMEWORK["LAZY_COMPONENT_MODULES"] = False
Keep LAZY_COMPONENT_MODULES: False (the default) in production so every component.py is imported during startup and registrations exist before traffic.
When True, each component.py is imported on the first render that resolves the component rather than during startup.
Component discovery and registration still happen eagerly in both modes.
Reference for lazy behaviour and testing helpers: Settings and Testing.
Static Backend¶
NEXT_FRAMEWORK["DEFAULT_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["DEFAULT_PAGE_BACKENDS"] = extend_default_backend(
"DEFAULT_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["DEFAULT_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,
"LAZY_COMPONENT_MODULES": False,
"DEFAULT_STATIC_BACKENDS": [
{"BACKEND": "notes.backends.CdnBackend", "OPTIONS": {}},
],
"JS_CONTEXT_SERIALIZER": "next.static.PydanticJsContextSerializer",
"DEFAULT_PAGE_BACKENDS": extend_default_backend(
"DEFAULT_PAGE_BACKENDS",
OPTIONS={"context_processors": [
"notes.context_processors.csp_nonce",
"notes.context_processors.tenant",
]},
),
"DEFAULT_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.