A company serves public JavaScript and CSS files from S3 using CloudFront. After a frontend change, customers report a low CloudFront cache hit ratio. Requests now include an Authorization header, but these assets do not require authentication. The CloudFront distribution is configured such that Authorization is included in the cache key. Which change best maximizes cache reuse?
Trap 1: Include the Authorization header in the cache key so responses vary…
Including Authorization in the cache key causes CloudFront to treat requests with different Authorization values (for example, different tokens per user) as different cache objects, fragmenting the cache and lowering hit ratio for public assets.
Trap 2: Disable caching and always fetch from S3
Disabling caching eliminates reuse and forces every request to hit the origin (higher latency and higher S3/origin load), which is the opposite of improving cache hit ratio.
Trap 3: Forward all headers and cookies to the origin to improve correctness
Forwarding extra headers/cookies typically increases cache fragmentation unless they are excluded from the cache key. For public static assets, forwarding does not improve cache reuse and usually worsens hit ratio.
- A
Include the Authorization header in the cache key so responses vary correctly
Why wrong: Including Authorization in the cache key causes CloudFront to treat requests with different Authorization values (for example, different tokens per user) as different cache objects, fragmenting the cache and lowering hit ratio for public assets.
- B
Use a CloudFront Cache Policy that excludes Authorization from the cache key
Because the assets are public and do not depend on Authorization, excluding Authorization from the cache key allows all users to share the same cached objects. This reduces cache fragmentation and increases cache hit ratio.
- C
Disable caching and always fetch from S3
Why wrong: Disabling caching eliminates reuse and forces every request to hit the origin (higher latency and higher S3/origin load), which is the opposite of improving cache hit ratio.
- D
Forward all headers and cookies to the origin to improve correctness
Why wrong: Forwarding extra headers/cookies typically increases cache fragmentation unless they are excluded from the cache key. For public static assets, forwarding does not improve cache reuse and usually worsens hit ratio.