We are busy developing a game for client who requires cache busting to be disabled for the final release build of the game. Is there anyway to turn this functionality off in published builds? When we run the downloaded game we can see that assets are requested with a timestamp parameter on the published builds:
So one way to fix this in your downloaded build is to go to __start__.js and at the top of the file add this code:
pc.Asset.prototype.getFileUrl = function () {
var file = this.getPreferredFile();
if (! file || ! file.url)
return null;
var url = file.url;
if (this.registry && this.registry.prefix && ! ABSOLUTE_URL.test(url))
url = this.registry.prefix + url;
return url;
};
This essentially patches the getFileUrl method to not append the timestamp in the end. One downside is that you have to do this every time you download a new build or basically anytime you need to upload your new build to your client’s server, but it’s the quickest solution for now.
Excellent! Thank you very much. I’ll give this a try. We have a modified version of __start__.js anyway as we had to integrate with the client’s API and make certain calls during startup, so this will be handled as part of our existing workflow.
Cool - obviously a problem with this approach is that if we change getFileUrl then you won’t get the updated code because you’re patching it.
A safer thing to do might be to store a reference to the old getFileUrl, call the old one inside the patched version and remove the timestamp from the result. That’s slower than not adding the timestamp at all but at least you don’t run the risk of having outdated code at some point.
That said we do patch some functions ourselves in various projects that need a quick fix sometimes.
Hi - this is the ABSOLUTE_URL regex from engine/src/asset/asset.js. Pasting it here for reference:
var ABSOLUTE_URL = new RegExp(
'^' + // beginning of the url
'\\s*' + // ignore leading spaces (some browsers trim the url automatically, but we can't assume that)
'(?:' + // beginning of protocol scheme (non-captured regex group)
'[a-z]+[a-z0-9\\-\\+\\.]*' + // protocol scheme must (RFC 3986) consist of "a letter and followed by any combination of letters, digits, plus ("+"), period ("."), or hyphen ("-")."
':' + // protocol scheme must end with colon character
')?' + // end of optional scheme group, the group is optional since the string may be a protocol-relative absolute URL
'//', // a absolute url must always begin with two forward slash characters (ignoring any leading spaces and protocol scheme)
'i' // non case-sensitive flag
);
Looks like getPreferredFile() has been removed now, so that this method no longer works with downloaded builds. Is there an alternative we could try? Ideally there would be a way in the editor to disable cache busting entirely.
Edit: Oh, Vaios already suggested this with the issue mentioned. It’s possible to patch this still but do it manually after downloading the build or add a conditional to applying the patch if its not being launched from the launch tab URL