playcanvas / engine

JavaScript game engine built on WebGL, WebGPU, WebXR and glTF
https://playcanvas.com
MIT License
9.69k stars 1.36k forks source link

Allow cache-busting parameter to be disabled for asset loading #3392

Open 403-Fruit opened 3 years ago

403-Fruit commented 3 years ago

Description

Asset files are loaded with a URL parameter (?t=...), added by the Asset.getFileUrl function. Here's the relevant code, from src/asset/asset.js:

getFileUrl() {
  ...
  // add file hash to avoid hard-caching problems
  if (this.type !== 'script' && file.hash) {
      var separator = url.indexOf('?') !== -1 ? '&' : '?';
      url += separator + 't=' + file.hash;
  }

There doesn't appear to be any way to disable this. This can cause issues in a lot of configurations (CDNs, service workers, etc), and can make it very difficult to set up specific caching behaviors for production. It also produces a lot of noise in server/devtools logs.

It would be great if we could get a configuration option (maybe in __settings__.js?) to disable this.

yaustar commented 3 years ago

This may need an Editor component too 🤔

As a temporary workaround, you can monkey patch the function in the PlayCanvas project so that the hash is not added or post process the config.json file and remove the hashes.