CachingHeaders
A plugin that adds the capability to configure the Cache-Control
and Expires
headers used for HTTP caching. The example below shows how to add the Cache-Control
header with the max-age
option for CSS and JSON:
install(CachingHeaders) {
options { call, outgoingContent ->
when (outgoingContent.contentType?.withoutParameters()) {
ContentType.Text.CSS -> CachingOptions(CacheControl.MaxAge(maxAgeSeconds = 3600))
ContentType.Application.Json -> CachingOptions(CacheControl.MaxAge(maxAgeSeconds = 60))
else -> null
}
}
}
Content copied to clipboard
You can learn more from Caching headers.