Skip to content

Commit e8da5e7

Browse files
committed
Loader - IE9 XDR used for all XHR when requested
Previously XHD was special-cased for 'json' file assets, but not all JSON requests. Now it is used for all XHR transfers when `useXDomainRequest` is enabled. If XDR is used outside of IE 9 then a warning is emitted to the console. The `useXDomainRequest` property has also been deprecated This may address consistency issues as mentioned in phaserjs#1361
1 parent ad08c7d commit e8da5e7

1 file changed

Lines changed: 31 additions & 12 deletions

File tree

src/loader/Loader.js

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,20 @@ Phaser.Loader = function (game) {
120120
this.onFileError = new Phaser.Signal();
121121

122122
/**
123-
* If true and if the browser supports XDomainRequest, it will be used in preference for XHR when loading JSON files (it does not affect other file types).
124-
* This is only relevant for IE9 and should only be enabled when required by the server/CDN.
123+
* If true and if the browser supports XDomainRequest, it will be used in preference for XHR.
124+
*
125+
* This is only relevant for IE 9 and should _only_ be enabled for IE 9 clients when required by the server/CDN.
125126
*
126127
* @property {boolean} useXDomainRequest
128+
* @deprecated This is only relevant for IE 9.
127129
*/
128130
this.useXDomainRequest = false;
129131

132+
/**
133+
* @property {boolean} _warnedAboutXDomainRequest - Control number of warnings for using XDR outside of IE 9.
134+
*/
135+
this._warnedAboutXDomainRequest = false;
136+
130137
/**
131138
* If true then parallel downloading will be enabled.
132139
* @property {integer} enableParallel
@@ -1445,14 +1452,7 @@ Phaser.Loader.prototype = {
14451452

14461453
case 'json':
14471454

1448-
if (this.useXDomainRequest && window.XDomainRequest)
1449-
{
1450-
this.xhrLoadWithXDR(file, this.transformUrl(file.url, file), 'text', this.jsonLoadComplete);
1451-
}
1452-
else
1453-
{
1454-
this.xhrLoad(file, this.transformUrl(file.url, file), 'text', this.jsonLoadComplete);
1455-
}
1455+
this.xhrLoad(file, this.transformUrl(file.url, file), 'text', this.jsonLoadComplete);
14561456
break;
14571457

14581458
case 'xml':
@@ -1579,7 +1579,8 @@ Phaser.Loader.prototype = {
15791579

15801580
/**
15811581
* Starts the xhr loader.
1582-
* This is designed specifically to use with asset files.
1582+
*
1583+
* This is designed specifically to use with asset file processing.
15831584
*
15841585
* @method Phaser.Loader#xhrLoad
15851586
* @private
@@ -1591,6 +1592,12 @@ Phaser.Loader.prototype = {
15911592
*/
15921593
xhrLoad: function (file, url, type, onload, onerror) {
15931594

1595+
if (this.useXDomainRequest && window.XDomainRequest)
1596+
{
1597+
this.xhrLoadWithXDR(file, url, type, onload, onerror);
1598+
return;
1599+
}
1600+
15941601
var xhr = new XMLHttpRequest();
15951602
xhr.open("GET", url, true);
15961603
xhr.responseType = type;
@@ -1624,7 +1631,9 @@ Phaser.Loader.prototype = {
16241631

16251632
/**
16261633
* Starts the xhr loader - using XDomainRequest.
1627-
* This is designed specifically to use with asset files.
1634+
* This should _only_ be used with IE 9. Phaser does not support IE 8 and XDR is deprecated in IE 10.
1635+
*
1636+
* This is designed specifically to use with asset file processing.
16281637
*
16291638
* @method Phaser.Loader#xhrLoad
16301639
* @private
@@ -1633,9 +1642,19 @@ Phaser.Loader.prototype = {
16331642
* @param {string} type - The xhr responseType.
16341643
* @param {function} onload - The function to call on success. Invoked in `this` context and supplied with `(file, xhr)` arguments.
16351644
* @param {function} [onerror=fileError] The function to call on error. Invoked in `this` context and supplied with `(file, xhr)` arguments.
1645+
* @deprecated This is only relevant for IE 9.
16361646
*/
16371647
xhrLoadWithXDR: function (file, url, type, onload, onerror) {
16381648

1649+
// Special IE9 magic .. only
1650+
if (!this._warnedAboutXDomainRequest &&
1651+
(!this.game.device.ie || this.game.device.ieVersion >= 10))
1652+
{
1653+
this._warnedAboutXDomainRequest = true;
1654+
console.warn("Phaser.Loader - using XDomainRequest outside of IE 9");
1655+
}
1656+
1657+
// Ref: http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx
16391658
var xhr = new window.XDomainRequest();
16401659
xhr.open('GET', url, true);
16411660
xhr.responseType = type;

0 commit comments

Comments
 (0)