Caching Headers

    To install the CachingHeaders feature, pass it to the install function in the application initialization code. This can be the main function …

    … or a specified module:

    To configure the CachingHeaders feature, you need to define the function to provide specified caching options for a given content type. The code snippet below shows how to add the header with the max-age option for CSS:

    The CachingOptions object accepts Cache-Control and Expires header values as parameters:

    • The expires parameter allows you to specify the Expires header as a GMTDate or ZonedDateTime value.

    If you need to add caching headers for a specific route only, you can append the desired headers into a response. In this case, you don’t need to CachingHeaders. The code snippet below shows how to disable caching for the /profile route: