apachegoogle-chromeaemdispatcher

Caching Videos Returning 206 on AEM Dispatcher running on Apache server


We are facing issues while trying to cache videos on AEM Dispatcher. We are running dispatcher 4.1.2 on Apache 2.2 http server.

The videos are being served properly and are working on all browsers, however they are NOT being cached when viewed from Chrome/Firefox, however are properly cached when viewed from IE. The difference that we see between browsers is that when the user opens video on IE, it completely loads the full video first and then start playing and hence returning 200 as response code. When chrome/firefox plays the videos, it uses range request and the full videos gets loaded by the browser in multiple range request returning 206 as response code.

This is all I know till now and I suspect due to partial requests made by chrome/firefox, the dispatcher does not cache the video.

Any pointers to resolve this issue would be really helpful!


Solution

  • However, we personally skipped caching videos on dispatcher as we are now using CDN to cache the videos, but if someone is interested in caching videos on dispatcher as well, here is the proposed solution that I haven't implemented yet, but in theory should work.

    Video Caching Works Based on Browser Behavior: Dispatcher is used to cache items like images/pages/videos etc. and there are certain conditions under which dispatcher caches the content that it serves, one of which is – Response Code should be 200. Now when the videos is played in different browsers, it uses different approach to play videos.

    When video is played using Chrome and Firefox, it uses Partial Content strategy to load and play video, i.e. it sends a request to the server to get only a part of video to quickly start playing it and in this case it sends a range header with the request which returns a part of the video with status code 206(success with partial content). So to play a video the browser(Chrome and Firefox) makes multiple range request, each of which returns a 206 status code and has a part of the video, due to which video doesn’t get cached when accessed through these browsers. The browser itself manages to play the whole video by combining these parts.

    Now in case of IE, the behavior is a little different. Instead of making partial range requests, it makes request to download the full video first and only after the whole video is downloaded, it starts playing the video. So in this case, the server returns the video file with status code as 200, which dispatcher sees as cacheable and hence caches the video. So when the video will be played by IE browser, it would be cached due to this behavior.

    Possible Solution: So based on behavior explained above, the videos when played with Chrome/Firefox won’t be cached on dispatcher while same videos when played with IE would be cached. Now, in case we still want to make the video cache, irrespective of the browser in which it is played we have to mock the IE behavior of the making requests to load the videos by implementing a special piece of code called as Cache Warming Script. This script won’t change browser behavior. This script will be triggered right after a video is activated from author which would trigger dispatcher flush event for that video, and we would catch this event and fire our script. This script will make a request to download full video with the same headers that IE uses, i.e. which in turn would automatically cache video on dispatcher. So all we are doing is making the video cache right after it is published and not waiting for it to be cached when it is played through browser.