DEV Community

insthync
insthync

Posted on

[Unity WebGL] How to make it not load content from cache

How to do it is like when you are going to force it to refresh style or javascript content by add GET parameter follow the files URL for example: version=007, script.js?v=1150. Then we may change parameters after files changed like this: script?v=1151

We can do the same thing with Unity build, in index.html file we can add GET parameter to file URL like following example which I've added id=20220704001

var buildUrl = "Build";
var loaderUrl = buildUrl + "/unity-build.loader.js?id=20220704001";
var config = {
  dataUrl: buildUrl + "/unity-build.data?id=20220704001",
  frameworkUrl: buildUrl + "/unity-build.framework.js?id=20220704001",
  codeUrl: buildUrl + "/unity-build.wasm?id=20220704001",
  streamingAssetsUrl: "StreamingAssets",
  companyName: "Insthync",
  productName: "Unity WebGL",
  productVersion: "0.1",
  showBanner: unityShowBanner,
};
Enter fullscreen mode Exit fullscreen mode

We also able to make Unity add GET parameter when builds with WebGL template macro like this:

var buildUrl = "Build";
var loaderUrl = buildUrl + "/{{{LOADER_FILENAME}}}?id={{{PRODUCT_VERSION}}}";
var config = {
  dataUrl: buildUrl + "/{{{DATA_FILENAME}}}?id={{{PRODUCT_VERSION}}}",
  frameworkUrl: buildUrl + "/{{{FRAMEWORK_FILENAME}}}?id={{{PRODUCT_VERSION}}}",
  codeUrl: buildUrl + "/{{{CODE_FILENAME}}}?id={{{PRODUCT_VERSION}}}",
  streamingAssetsUrl: "StreamingAssets",
  companyName: "{{{COMPANY_NAME}}}",
  productName: "{{{PRODUCT_NAME}}}",
  productVersion: "{{{PRODUCT_VERSION}}}",
  showBanner: unityShowBanner,
};
Enter fullscreen mode Exit fullscreen mode

If we set Version (in Build Settings) to 1.0 then when it built, codes in index.html will be like:

var buildUrl = "Build";
var loaderUrl = buildUrl + "/unity-build.loader.js?id=1.0";
var config = {
  dataUrl: buildUrl + "/unity-build.data?id=1.0",
  frameworkUrl: buildUrl + "/unity-build.framework.js?id=1.0",
  codeUrl: buildUrl + "/unity-build.wasm?id=1.0",
  streamingAssetsUrl: "StreamingAssets",
  companyName: "Insthync",
  productName: "Unity WebGL",
  productVersion: "1.0",
  showBanner: unityShowBanner,
};
Enter fullscreen mode Exit fullscreen mode

You can find more information about template macro from this link.


Addressable Asset not being refreshed?

We can do the same thing by make changes to StreamingAssets\aa\settings.json file.

Find {"m_Keys":["AddressablesMainContentCatalogRemoteHash"],"m_InternalId": in settings.json.

It will have codes like this "m_InternalId":"https://yourgameassets.com/addressable/WebGL/catalog_2022.07.04.00.00.00.hash"

Then just add GET parameter like this

"m_InternalId":"https://yourgameassets.com/addressable/WebGL/catalog_2022.07.04.00.00.00.hash?version=001"

Top comments (0)