Search code examples
nginxvideo-streaminghttp-live-streaming

Nginx Range Request in URL Query Parameters


I'm building an HLS/DASH streaming server and today I found out using single big files with range requests is better than many small files - It's what Netflix and YouTube currently doing.

But there is a problem; since I have a different domain for video CDN and the actual player page (eg. netflix.com - nflxvideo.net) CORS gets in and sends an OPTION request with every request. Because the player sends a lot of requests this wastes bytes.

Netflix (which also uses nginx) and YouTube fixed this with sending range in URL or query so browser doesn't send OPTION requests: https://xx.nflxvideo.net/range/0-64209238?o=...

I'm trying to achieve the same thing in Nginx but there isn't any way I could find for 4 hours. We have files stored in the server so we are using sendfile.

Thanks!


Solution

  • I couldn't find how to do this, but for the main goal of not wasting resources with OPTIONS requests, there is Access-Control-Max-Age header for caching the OPTIONS requests.

    Basically set it to Firefox's maximum of 86400 seconds (24 hours) and it's working.

    I skipped this header before because it was 10 minutes in Chrome, but apparently, it's increased to 2 hours since Chrome 76. It's more than enough since the average duration of our videos is 100 minutes.

    More info about the header is here.