Add cache-breaking string to remote requests
This commit is contained in:
@@ -1052,6 +1052,7 @@ class AssetCache {
|
||||
public var enabled:Bool = true;
|
||||
public var image:Map<String, Image>;
|
||||
public var font:Map<String, Dynamic /*Font*/>;
|
||||
public var version:Int;
|
||||
|
||||
|
||||
public function new () {
|
||||
@@ -1059,6 +1060,7 @@ class AssetCache {
|
||||
audio = new Map<String, AudioBuffer> ();
|
||||
font = new Map<String, Dynamic /*Font*/> ();
|
||||
image = new Map<String, Image> ();
|
||||
version = Std.int (Math.random () * 1000000);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -36,9 +36,7 @@ class Preloader #if flash extends Sprite #end {
|
||||
public function new () {
|
||||
|
||||
#if flash
|
||||
|
||||
super ();
|
||||
|
||||
super ();
|
||||
#end
|
||||
|
||||
onProgress.add (update);
|
||||
@@ -49,20 +47,16 @@ class Preloader #if flash extends Sprite #end {
|
||||
public function create (config:Config):Void {
|
||||
|
||||
#if flash
|
||||
|
||||
Lib.current.addChild (this);
|
||||
|
||||
Lib.current.loaderInfo.addEventListener (flash.events.Event.COMPLETE, loaderInfo_onComplete);
|
||||
Lib.current.loaderInfo.addEventListener (flash.events.Event.INIT, loaderInfo_onInit);
|
||||
Lib.current.loaderInfo.addEventListener (ProgressEvent.PROGRESS, loaderInfo_onProgress);
|
||||
Lib.current.addEventListener (flash.events.Event.ENTER_FRAME, current_onEnter);
|
||||
|
||||
Lib.current.addChild (this);
|
||||
|
||||
Lib.current.loaderInfo.addEventListener (flash.events.Event.COMPLETE, loaderInfo_onComplete);
|
||||
Lib.current.loaderInfo.addEventListener (flash.events.Event.INIT, loaderInfo_onInit);
|
||||
Lib.current.loaderInfo.addEventListener (ProgressEvent.PROGRESS, loaderInfo_onProgress);
|
||||
Lib.current.addEventListener (flash.events.Event.ENTER_FRAME, current_onEnter);
|
||||
#end
|
||||
|
||||
#if (!flash && !html5)
|
||||
|
||||
start ();
|
||||
|
||||
start ();
|
||||
#end
|
||||
|
||||
}
|
||||
@@ -71,73 +65,74 @@ class Preloader #if flash extends Sprite #end {
|
||||
public function load (urls:Array<String>, types:Array<AssetType>):Void {
|
||||
|
||||
#if (js && html5)
|
||||
|
||||
var url = null;
|
||||
var cacheVersion = Assets.cache.version;
|
||||
|
||||
for (i in 0...urls.length) {
|
||||
|
||||
var url = null;
|
||||
url = urls[i];
|
||||
|
||||
for (i in 0...urls.length) {
|
||||
switch (types[i]) {
|
||||
|
||||
url = urls[i];
|
||||
|
||||
switch (types[i]) {
|
||||
case IMAGE:
|
||||
|
||||
case IMAGE:
|
||||
|
||||
if (!images.exists (url)) {
|
||||
|
||||
var image = new Image ();
|
||||
images.set (url, image);
|
||||
image.onload = image_onLoad;
|
||||
image.src = url;
|
||||
total++;
|
||||
|
||||
}
|
||||
|
||||
case BINARY:
|
||||
|
||||
if (!loaders.exists (url)) {
|
||||
|
||||
var loader = new URLLoader ();
|
||||
loader.dataFormat = BINARY;
|
||||
loaders.set (url, loader);
|
||||
total++;
|
||||
|
||||
}
|
||||
|
||||
case TEXT:
|
||||
|
||||
if (!loaders.exists (url)) {
|
||||
|
||||
var loader = new URLLoader ();
|
||||
loaders.set (url, loader);
|
||||
total++;
|
||||
|
||||
}
|
||||
|
||||
case FONT:
|
||||
if (!images.exists (url)) {
|
||||
|
||||
var image = new Image ();
|
||||
images.set (url, image);
|
||||
image.onload = image_onLoad;
|
||||
image.src = url + "?" + cacheVersion;
|
||||
total++;
|
||||
loadFont (url);
|
||||
|
||||
}
|
||||
|
||||
case BINARY:
|
||||
|
||||
default:
|
||||
if (!loaders.exists (url)) {
|
||||
|
||||
var loader = new URLLoader ();
|
||||
loader.dataFormat = BINARY;
|
||||
loaders.set (url, loader);
|
||||
total++;
|
||||
|
||||
}
|
||||
|
||||
case TEXT:
|
||||
|
||||
}
|
||||
if (!loaders.exists (url)) {
|
||||
|
||||
var loader = new URLLoader ();
|
||||
loaders.set (url, loader);
|
||||
total++;
|
||||
|
||||
}
|
||||
|
||||
case FONT:
|
||||
|
||||
total++;
|
||||
loadFont (url);
|
||||
|
||||
default:
|
||||
|
||||
}
|
||||
|
||||
for (url in loaders.keys ()) {
|
||||
|
||||
var loader = loaders.get (url);
|
||||
loader.onComplete.add (loader_onComplete);
|
||||
loader.load (new URLRequest (url));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
for (url in loaders.keys ()) {
|
||||
|
||||
if (total == 0) {
|
||||
|
||||
start ();
|
||||
|
||||
}
|
||||
var loader = loaders.get (url);
|
||||
loader.onComplete.add (loader_onComplete);
|
||||
loader.load (new URLRequest (url + "?" + cacheVersion));
|
||||
|
||||
}
|
||||
|
||||
if (total == 0) {
|
||||
|
||||
start ();
|
||||
|
||||
}
|
||||
|
||||
#end
|
||||
|
||||
}
|
||||
@@ -344,4 +339,4 @@ class Preloader #if flash extends Sprite #end {
|
||||
#end
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -590,7 +590,7 @@ class DefaultAssetLibrary extends AssetLibrary {
|
||||
promise.error (e);
|
||||
|
||||
});
|
||||
loader.load (new URLRequest (path.get (id)));
|
||||
loader.load (new URLRequest (path.get (id) + "?" + Assets.cache.version));
|
||||
|
||||
} else {
|
||||
|
||||
@@ -657,7 +657,7 @@ class DefaultAssetLibrary extends AssetLibrary {
|
||||
|
||||
}
|
||||
image.onerror = promise.error;
|
||||
image.src = path.get (id);
|
||||
image.src = path.get (id) + "?" + Assets.cache.version;
|
||||
|
||||
} else {
|
||||
|
||||
@@ -770,7 +770,7 @@ class DefaultAssetLibrary extends AssetLibrary {
|
||||
|
||||
});
|
||||
loader.onIOError.add (function (_, msg) promise.error (msg));
|
||||
loader.load (new URLRequest (path.get (id)));
|
||||
loader.load (new URLRequest (path.get (id) + "?" + Assets.cache.version));
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user