Search code examples
expresskeystonejs

Does setting node_env=production handle conditional templates?


I am using a lot of nunjucks templates and custom api endpoints with keystone. Does setting node_env=production cache template return data, especially since it has a lot of dynamic info. Does it cache the rendered or just template file? Also, what about custom /api endpoints ... assuming that data is not cached? How about database results? Thanks for any info.


Solution

  • The NODE_ENV setting is an Express convention, so the effects apply to Express and related middleware rather than Keystone core. If you have added any Express middleware packages, you'll have to check their usage documentation for possible behaviour changes.

    Setting NODE_ENV to “production” makes Express:

    • Cache view templates.
    • Cache CSS files generated from CSS extensions.
    • Generate less verbose error messages.

    I am using a lot of nunjucks templates and custom api endpoints with keystone. Does setting node_env=production cache template return data, especially since it has a lot of dynamic info. Does it cache the rendered or just template file?

    Express only caches the view templates in memory, not the rendered result. Pages will still be re-rendered on every request using relevant variables. There's a note about this buried at the bottom of Express' Using Template Engines documentation.

    what about custom /api endpoints ... assuming that data is not cached?

    Express does not do not include any caching for API endpoints by default.

    How about database results?

    The MongoDB Node.js driver (and Mongoose ODM) do not cache query results.