How to cache the compressed responses?
Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the feature has not already been requested
🚀 Feature Proposal
I assume there is a not insignificant overhead of using compression.
Instead, it would be cheaper to cache (or even store on disk) copies of the compressed content.
Is there a hook or another method I could use to achieve this instead of cache-ing every asset adhoc?
Motivation
No response
Example
No response
Generically, this is better done at the CDN/reverse proxy level by using the Cache-Control headers at the application level. What makes caching the compressed data hard for this module is knowing when to serve the cached response.
To know if we can serve the cached response, we need to hash the original version, but to do so, we need to have it fully in memory. If it is a small payload, it's likely better to transfer it uncompressed. Larger payloads usually must be sent as stream; otherwise, it would exhaust the memory, but if they are streams, we won't know their full hash before we have read them fully.
See precompressed: https://github.com/fastify/fastify-static?tab=readme-ov-file#precompressed
It partially achieves your desired behavior