Streaming XHR cache control

In Internet Explorer 11 you have more control over whether or not data you download using XMLHttpRequest (XHR) is written to the disk, or cached, before it's passed to the video control using the msCaching attribute.

When you download video data using XHR, you can use the msCaching attribute to control whether to write the data to disk (cache), or not, to save power and decrease playback latency.

By not caching data streamed using XHR, you can get better battery life on tablets and laptops, and avoid disk latency bottlenecks.

You can specify automatic or manual msCaching values for stream responses. Use msCaching to set the caching state, and use the msCachingEnabled() method to get the current state.


xhr.msCaching = ['auto'|'enabled'|'disabled']   // sets caching state (default is disabled)
var cachingState = xhr.msCachingEnabled();  // reads current caching state (true|false)

The msCaching attribute has the following states for different types of responseTypes:

StateResponse typemsCachingEnabled()
autostream|ms-streamfalse
enabledstream|ms-streamtrue
auto|enabledarraybuffer|blob|document|json|texttrue
disabledany typefalse

 

The msCaching attribute lets you get or set whether IE11 caches to the disk (true) or not (false).

When msCachingEnabled() returns false, XHR streams won't be cached to disk. When msCachingEnabled() returns true, XHR operates the same way it did in Internet Explorer 10. When caching is enabled, IE11 honors any cache control mechanisms, such as cache-control headers. This means that the msCaching XHR attribute can't be used to force caching when it wouldn't happen otherwise.

By default, IE11 automatically skips disk caching when you select a stream response type, even if the msCaching attribute isn't set. This snippet shows the default msCaching = disabled state.


        var xhr = new XMLHttpRequest();
        xhr.open('GET', url, true);
        xhr.responseType = 'stream';  
        xhr.send();


This example sets caching to enabled so it operates as it does in Internet Explorer 10


        var xhr = new XMLHttpRequest();
        xhr.open('GET', url, true);
        xhr.msCaching = 'enabled';  
        xhr.responseType = 'stream';  
        xhr.send();


Note  You can set msCaching only when XHR is in the OPENED state. If you violate this rule, an InvalidStateError exception is thrown.

Related topics

XMLHttpRequest
msCaching
msCachingEnabled

 

 

Show:
© 2014 Microsoft. All rights reserved.