How can I stop X-Sendfile from serving the full video file when IE9 makes the request?

389 Views Asked by At

I ran into an issue where regardless of the preload attribute setting, when IE9 makes a request for a video, and the video is served by x-sendfile, the request is listed as pending and keeps the connection open.

Consequently, if you have 10 videos trying to load, IE9 will quickly eat up all of its available connections and the browser will not be able to make further requests.

When telling IE9 to request the same video from Apache, without X-Sendfile, Apache serves a small portion of the file as a 200 request. Then the browser makes a request later when the play button is pressed to serve a range of the file.

It looks like X-Sendfile is causing Apache to serve the entire file initially, instead of serving just a part of it.

How can I make X-Sendfile requests via Apache function the same as a regular request to Apache?

1

There are 1 best solutions below

2
On

Setting the "Accept-Ranges" header like header("Accept-Ranges: bytes"); tells IE9 to attempt to stream the file by default, instead of serve it in one chunk.

It's recommended to check that the HTTP request is version 1.1 though before setting, since 1.0 doesn't support the header.

if (isset($_SERVER['SERVER_PROTOCOL']) && $_SERVER['SERVER_PROTOCOL'] === 'HTTP/1.1') {
    header("Accept-Ranges: bytes");
}

I wasn't able to find any documentation on this anywhere, so I'm posting my solution here.