DEV Community

insthync
insthync

Posted on

2 2

[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"

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay