[SOLVED] Disable cache busting


#1

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:

127.0.0.1 - - [09/Jun/2017 15:19:11] “GET /files/assets/8121498/1/canyon-tile-02.json?t=ec52eea3badfdf70eb30761865296d80 HTTP/1.1” 200 -
127.0.0.1 - - [09/Jun/2017 15:19:11] “GET /files/assets/8121730/1/planet-tile-04.json?t=551b8c0fb87a6168399e1d61c050d81a HTTP/1.1” 200 -
127.0.0.1 - - [09/Jun/2017 15:19:11] “GET /files/assets/8121732/1/planet-tile-02.json?t=9419324c5d5d0dff179a59166febb387 HTTP/1.1” 200 -
127.0.0.1 - - [09/Jun/2017 15:19:11] “GET /files/assets/8121734/1/planet-tile-05.json?t=212e2f7b7feef6e9437c10b47591f1e9 HTTP/1.1” 200 -
127.0.0.1 - - [09/Jun/2017 15:19:11] “GET /files/assets/8121736/1/planet-tile-03.json?t=18e0bb6534d2b367e3a2e78141210d35 HTTP/1.1” 200 -
127.0.0.1 - - [09/Jun/2017 15:19:11] “GET /files/assets/8121743/1/planet-tile-01.json?t=666f9d9c31bbd8416377f38ae68bd2ed HTTP/1.1” 200 -
127.0.0.1 - - [09/Jun/2017 15:19:11] “GET /files/assets/8122276/1/asset.glsl?t=aac6601a86ad36eada340d172d6740b0 HTTP/1.1” 200 -
127.0.0.1 - - [09/Jun/2017 15:19:11] “GET /files/assets/8122277/1/asset.glsl?t=31a1cfcd515c07db8e4f399e4d2b75ba HTTP/1.1” 200 -
127.0.0.1 - - [09/Jun/2017 15:19:11] “GET /files/assets/8122988/1/canyon-tile-06.json?t=72abc7acf2a2e76d6d5af3e350090dc4 HTTP/1.1” 200 -
127.0.0.1 - - [09/Jun/2017 15:19:11] “GET /files/assets/8122990/1/canyon-tile-07.json?t=3f6d8c5a06e28aadb080933cf4879afa HTTP/1.1” 200 -
127.0.0.1 - - [09/Jun/2017 15:19:11] “GET /files/assets/8122993/1/canyon-tile-05.json?t=6f793338d831bfc7021711a7323c5eef HTTP/1.1” 200 -
127.0.0.1 - - [09/Jun/2017 15:19:11] “GET /files/assets/8126836/1/tokyo.json?t=0f320242708c9e8facd0bbec2852360e HTTP/1.1” 200 -
127.0.0.1 - - [09/Jun/2017 15:19:11] “GET /files/assets/8126841/1/toyko-tile-02.json?t=a00be6ddf81e760892646081c63438d2 HTTP/1.1” 200 -
127.0.0.1 - - [09/Jun/2017 15:19:11] “GET /files/assets/8126843/1/toyko-tile-01.json?t=9890ce913ab41590d0fa48bc21ce3a2c HTTP/1.1” 200 -
127.0.0.1 - - [09/Jun/2017 15:19:11] “GET /files/assets/8126845/1/toyko-tile-03.json?t=22a32b5fefcaa9f73d7eb0b2563d40a8 HTTP/1.1” 200 -
127.0.0.1 - - [09/Jun/2017 15:19:11] “GET /files/assets/8127223/1/subway-tile-01.json?t=7d1d33f3e563526297a0780a91174b9d HTTP/1.1” 200 -


#2

Looking into this…


#3

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.


#4

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.


#5

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.


#6

Great!
But sorry, what is “ABSOLUTE_URL”.
I cannot run this code on the current playcanvas.


#7

Is this release product url?


#8

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
);