js_preload_object
The `js_preload_object` directive in NGINX enables preloading NJS objects for use in JavaScript execution contexts.
Description
The js_preload_object directive allows you to define JavaScript objects that should be preloaded when the NGINX server starts, making them available for use in your JavaScript code without needing to dynamically load or initialize them during request processing. This can enhance performance by reducing overhead associated with object creation during high-throughput scenarios.
The directive takes either one argument, giving a single object name to preload, or three, specifying additional attributes related to the object. In contexts such as stream and stream server, this directive can help manage non-blocking NGINX streams efficiently by ensuring the necessary objects are already in memory when they are needed.
Config Example
js_preload_object my_object { attributes };Ensure that the script defining the object is loaded before using js_preload_object.
Using the wrong context may lead to unexpected behavior or errors.
Preloading excessive objects can consume unnecessary memory and affect performance.