Consistent caching of videos using HTML5
search cancel

Consistent caching of videos using HTML5


Article ID: 165609


Updated On:


ProxySG Software - SGOS


Currently, it's possible to transparently set a cookie in the client’s browser to automatically enable “HTML5 mode” when visiting This can present a major advantage, since with the new HTML5 video content type it's easier to cache YouTube videos without any need for RTMP proxy or more complex CPL code.




  1. This is a service provided by and as such they may change it at any time. The “HTML5 mode” is still considered to be a trial and so we can expect this to change; in this case, the procedure described here may need updating or modification. However we do expect HTML5 to be more prevalent as time goes by, so this document provides a valid starting point. This document serves as a Proof of Concept of what the proxy can achieve if traffic patterns are observed.
  2. Please read Make a special note of which browsers currently support HTML5 and make sure clients are using a HTML5 capable browser. Also note that YouTube states:

                       “Videos with ads are not supported (they will play in the Flash player)”

             This means that the same video may sometimes play in Flash because an ad will be displayed. Other times it will play in HTML5. There is no possibility in controlling this until YouTube enables HTML5 for their advertisements also.

CPL code:

Ensure that the proxy is intercepting HTTP traffic. Add the following CPL code to your local policy file (see comments inline):


;if the HTML5 preference cookie is not present, instruct the client to set this cookie

<Proxy> request.header.Cookie=!".*PREF.*f2.*" action.set_HTML5_cookie(yes)


;by detecting if the HTML5 “video” content is detect, force the proxy to cache this HTTP object


    condition=html5_video_tag force_cache(yes)


; Definitions

define condition html5_video_tag





define action set_HTML5_cookie

  set( response.header.Set-Cookie, "PREF=f2=40000000; path=/;;" )




How can you tell if the above policy works and the browser is using HTML5 mode?

Using the browser, navigate to Even though the client never “opted-in,” you should see this:



How can I tell if a specific video being played is actually using HTML5?

When viewing the video, right click on the video. If the video is using the normal Flash you will see a Flash context menu:


On the other hand, if the video is using HTML5, the menu will relate to HTML5:


How can we see the caching gains that HTML5 introduces?

This can be seen in the Active Sessions report on the ProxySG (Statistics > Sessions > Active Sessions). The first time a video is accessed in HTML5 you will see no gains; this is expected:


However, the second time a user requests this video, you should see 80-100% savings:


Note how the proxy is serving the object from cache.

General Observations

         - Even with the above CPL in place, browsers that do not support HTML5 will not break. They will simply fall back to the Flash Player. 

         - The first time a user requests a video in HTML5, there may be a longer delay than normal in serving the video than when accessing the video in Flash:






This is to be expected because the proxy is requesting the video from the server and must wait until it completely caches the object before serving it to the client. However, once past this stage, the video is fully buffered, as will be subsequent visits to the same video. The delay depends on the speed of the WAN link and the size of the video.

         - Ensure that the Do not cache objects larger than setting is not set too low:



              Some of these videos can get quite large, so make sure to find a balance between what you need to cache and what is considered too large to cache.

        -  This may change in the future, but until now streaming video remains using Flash or RTMP, so there are no splitting benefits or similar.