Easy '304 Not Modified' Responses

Estimated reading time: 1 minute

ConditionalHeaders feature adds the ability to avoid sending content if the client already has the same content. It does so by checking the ETag or LastModified properties of the Resource or FinalContent that are sent and comparing these properties to what client indicates it is having. If the conditions allow it, the entire content is not sent and a “304 Not Modified” response is sent instead.

install(ConditionalHeaders)
This feature is defined in the class io.ktor.features.ConditionalHeaders and no additional artifacts are required.

Configuration

This feature doesn’t have any configuration object, but a configuration script is executed if present.

Extensibility

Version interface implementations are attached to the Resource instances, and you can return custom implementations with your own logic. Please note that FinalContent is only checked for ETag and LastModified headers.