media server logo

How to Cache HLS Fragments Correctly in CloudFront

Jun 05, 2024

After CloudFront is in front of the HLS origin, caching behavior becomes the next important control point. This page is about that tuning layer: not how to create the distribution, but how to make manifests and media fragments behave correctly under live delivery.

If you have not built the distribution yet, start with CloudFront setup on AWS. If you are starting one step earlier from contribution ingest, the broader route is SRT -> HLS -> CloudFront.

Why HLS caching needs special handling

HLS is not just a single video file. It includes manifests and media fragments, and those objects do not all behave the same way. If caching is too aggressive or too loose in the wrong place, viewer playback becomes stale, unstable, or unnecessarily expensive.

Step 1. Open the CloudFront behavior for the HLS path

Go to the part of the distribution where behavior for HLS requests is controlled.

Step 2. Separate manifests from media fragments conceptually

Manifests change more often and usually need tighter freshness rules than media fragments. This is the key mental model for HLS caching in a CDN.

Step 3. Review fragment path behavior

Make sure the fragment paths are being handled with caching behavior that fits live delivery rather than generic web asset defaults.

Step 4. Verify that playback stays current

Test the playback path and confirm that the HLS stream advances correctly instead of serving stale manifest state or fragment behavior that lags behind the live edge.

What usually breaks

  • the same cache assumptions are applied to manifests and fragments
  • CloudFront is configured before the HLS path is validated at origin
  • teams optimize for cache hit rate without protecting live playback freshness

Once caching works correctly, CloudFront becomes a much stronger delivery layer for large viewer counts because the CDN is no longer fighting the shape of the HLS stream itself.

Final practical rule

For live HLS, correct caching is not a minor optimization. It is part of playback correctness. Tune manifests and fragments intentionally, or the CDN will amplify the wrong behavior instead of scaling the right one.