Skip to content

Commit

Permalink
Use configure to disable cache-busting
Browse files Browse the repository at this point in the history
This does not mean that Shaka v1 is suddenly cache-friendly, but this
gives users the option to weigh the problems caused by caching in
Shaka v1 against the problems caused by the cache-buster for certain
CDNs or authentication schemes.  Previously, this would have required
local changes.  Now it can be done in a standard build.

The parameter name is extra long and wordy to make sure that it cannot
be used without acknowledging that there are trade-offs involved.

Closes #235, #238, #76

Change-Id: I934a5703183d31250458b80cb38d2b5deae410df
joeyparrish committed Dec 13, 2015
1 parent c9f8ab5 commit ef3e38a
Showing 2 changed files with 37 additions and 9 deletions.
22 changes: 22 additions & 0 deletions lib/player/player.js
Original file line number Diff line number Diff line change
@@ -711,6 +711,22 @@ shaka.player.Player.prototype.isLive = function() {
* Sets the video track restrictions. For example, if minBandwidth = 200000
* and maxBandwidth = 700000 then the player will only permit switching to
* video tracks with bandwidths between 200000 and 700000.
*
* <li>
* <b>disableCacheBustingEvenThoughItMayAffectBandwidthEstimation</b>: boolean
* <br>
* Disables all use of cache-busting parameters, even though it may affect
* bandwidth estimation. This is a stop-gap measure for Shaka v1, since many
* people have had issues with the cache-busting parameters we typically add
* to network requests. Shaka v2 will be cache-friendly by default.
* <br>
* Please note that Shaka v1's bandwidth estimation algorithm can be adversely
* affected by caching, in particular when seeking in low-bandwidth
* environments, such as mobile devices.
* <br>
* If cache-busting is a problem for your application or your CDN, use this
* parameter to disable it.
*
* </ul>
*
* @example
@@ -774,6 +790,12 @@ shaka.player.Player.prototype.configure = function(config) {
this.videoSourceConfig_['restrictions'] = restrictions.clone();
}

var disableCacheBusting = MapUtils.getBoolean(config,
'disableCacheBustingEvenThoughItMayAffectBandwidthEstimation');
if (disableCacheBusting != null) {
shaka.util.AjaxRequest.enableCacheBusting = !disableCacheBusting;
}

if (this.videoSource_) {
this.videoSource_.configure(this.videoSourceConfig_);
}
24 changes: 15 additions & 9 deletions lib/util/ajax_request.js
Original file line number Diff line number Diff line change
@@ -183,6 +183,10 @@ shaka.util.AjaxRequest.Parameters = function() {
};


/** @type {boolean} */
shaka.util.AjaxRequest.enableCacheBusting = true;


/**
* Destroys the AJAX request.
* This happens automatically after the internal promise is resolved or
@@ -246,15 +250,17 @@ shaka.util.AjaxRequest.prototype.send = function() {
this.xhr_ = new XMLHttpRequest();

var url = this.url;
if ((this.estimator && !this.estimator.supportsCaching()) ||
this.parameters.synchronizeClock) {
// We cannot detect that a response was cached after the fact, so add a
// cache-busting parameter to the request to avoid caching. There are
// other methods, but they do not work cross-origin without control over
// both client and server.
var modifiedUri = new goog.Uri(url);
modifiedUri.getQueryData().add('_', Date.now());
url = modifiedUri.toString();
if (shaka.util.AjaxRequest.enableCacheBusting) {
if ((this.estimator && !this.estimator.supportsCaching()) ||
this.parameters.synchronizeClock) {
// We cannot detect that a response was cached after the fact, so add a
// cache-busting parameter to the request to avoid caching. There are
// other methods, but they do not work cross-origin without control over
// both client and server.
var modifiedUri = new goog.Uri(url);
modifiedUri.getQueryData().add('_', Date.now());
url = modifiedUri.toString();
}
}

this.xhr_.open(this.parameters.method, url, true);

0 comments on commit ef3e38a

Please sign in to comment.