Video and large files
On this page
Video needs nothing switching on. A file up to 10 MB is stored whole and a larger one in 5 MB pieces fetched as it is watched. Either reaches the viewer as it arrives from your origin, so a viewer starting or seeking waits only for your origin's first bytes, never for a piece or the file, and your origin is asked only for the pieces viewers are watching.
How a large file is served#
- The first request for any file asks your origin for its first 10 MB (10,485,760 bytes) with a
Rangeheader, from the start of the file whatever range the viewer asked for. A file that fits is stored whole from that answer and a larger one as pieces from then on, and either way that first viewer is sent its bytes as they arrive (a text file the edge compresses with Brotli is compressed whole first: see How caching works). If that viewer moves elsewhere in the file before the 10 MB has arrived and nobody else is reading it, the rest of it is not fetched; nor is it when every viewer of the file has left for five seconds with less than half of a piece in. - Each piece is 5 MB. A viewer's request is served from the pieces it needs, and within the range a viewer asked for, once the viewer has taken its first megabyte, the edge fetches up to two pieces ahead of the one being played, so playback does not wait for your origin at every boundary.
- A seek into a part of the file the edge has not seen starts that piece's fetch, plus the two after it once the viewer has received its first megabyte, and the viewer is answered as soon as your origin starts sending; never the whole file. A seek more than 1 MB into a piece asks your origin for the piece from the viewer's byte first and for the part before it afterwards, so each byte is still asked for once. A seek also stops the fetches of the same file that no viewer is reading any more, such as the read-ahead of a viewer who seeked away, so your origin's bandwidth goes to what is being watched. A piece reaches the cache only when it is whole: one your origin stops sending part way is cut off for the viewer and fetched afresh next time.
- Viewers in the same location watching the same piece at the same time share one fetch, a viewer arriving mid-fetch reading what has arrived so far; with a Home PoP, one fetch serves every location. Video, audio and images are never compressed, so viewers whose players accept Brotli and viewers whose players do not share one copy (see How caching works).
- Files are stored up to 100 GB, which takes a long 4K film or a disc-quality remux. Only the pieces viewers watch are fetched and stored, whatever the file's size. Beyond 100 GB a file is passed through from your origin to the viewer, unstored.
What your origin needs#
Byte ranges. Every fetch of a large file carries a Range header and expects a 206, which web servers and object stores return by default. An origin that ignores Range and answers 200 with the whole file still works: files up to 10 MB are stored normally, and larger ones are passed through to the viewer without being stored, on every request, which costs origin bandwidth and denies viewers a shared copy, and each download holds one of your zone's places for requests to your origin for as long as it lasts, so a popular file can meet the 503 a busy zone gets. Check with curl -sI -H "Range: bytes=0-0" https://origin.example.com/film.mp4: the answer should be 206 with a Content-Range header.
Give files an ETag or a Last-Modified header, which every server does by default. The edge sends it back with each piece fetch as If-Range (a strong ETag, or else the Last-Modified date), so a file you replace at the origin is never spliced together from old and new pieces. The request that notices the change is answered with the 502 page, or cut off if it was already playing, the old pieces are dropped, and the next request fetches the new file. Purge the file or the zone after replacing it if you want the old pieces gone at once rather than at their expiry. See Purging.
Ranges from viewers#
A viewer's Range request is answered with a 206 and the bytes asked for, from the copy where the edge has them and from your origin where it does not. One range per request: a request for several ranges at once is answered with the first of them, as a plain 206 rather than a multipart body. A range that starts past the end of the file gets 416 with a Content-Range: bytes */size header and no body. A malformed range gets the whole file with 200.
HLS and DASH#
Segments are files like any other and follow the rules above; under Respect Origin Cache-Control a segment whose origin sends no Cache-Control or Expires is kept for seven days. Playlists and manifests (.m3u8, .mpd) are held for 10 seconds under that setting unless your origin sends a max-age of its own, so a playlist that is still being written reaches viewers quickly; a fixed Cache expiration time applies to playlists too, with no cap, so a zone set to 1 Day holds a live playlist for a day. If you sign your links, sign the folder rather than the playlist, or the player's segment requests fail: see Token authentication. There is no ingest, no transcoding and no player: the edge delivers the files your origin serves, a playlist your encoder keeps rewriting included.
What is counted#
Your statistics and your invoice count the bytes delivered to viewers. The pieces the edge fetches from your origin, the ones it reads ahead included, and the part of one stopped because nobody was reading it, are origin traffic: shown on the statistics page as such and never charged. See Statistics.