Description
Please avoid duplicates
- I checked all open issues and discussions and none of them matched my problem.
Language and Compiler
Other JavaScript compiler
What environment are you using?
Server Side Renderering
When does your problem occur?
While the Unity App is loading
What does your problem relate to?
The problem seems React related
React-Unity-WebGL Version
9.5.1
React Version
18
Unity Version
2022.3.20f1
What happened?
Hello, i searched the world wide web in its entirety. My .unityweb files are not being loaded from cache at all. I tried everything, and in the documentation, there is a page dedicated to cacheControl, we added the function that handled the 'must-revalidate'. Plus we added console logs and made sure when on the server the when loading the url is reaching the 'must-revalidate'. One more thing we tried, before saying that this is a server issue, we ran the index.html file from the build folder on its own on a ubuntu nginx server (the same one serving the nextjs project) and it loaded the first time, the second time it loaded from cache and took 2 seconds. When using the react-unity-webgl it loads under all circumstances from the server and not cached!
Reproducible test case
function handleCaching(url) {
console.log("Entered handleCaching with url: ", url);
// Caching enabled for .data and .bundle files.
// Revalidate if file is up to date before loading from cache
if (
url.match(/\.data/) ||
url.match(/\.bundle/) ||
url.match(/\.wasm/) ||
url.match(/\.unityweb/)
) {
console.log("URL matched data or bundle: ", url);
return "must-revalidate";
}
// Caching enabled for .mp4 and .custom files
// Load file from cache without revalidation.
if (url.match(/\.mp4/) || url.match(/\.custom/)) {
return "immutable";
}
// Disable explicit caching for all other files.
// Note: the default browser cache may cache them anyway.
return "no-store";
}
const { unityProvider, loadingProgression, isLoaded } = useUnityContext({
loaderUrl: isMobile
? "BuildMobile/Build/Build.loader.js"
: "Build/Build/Build.loader.js",
dataUrl: isMobile
? "BuildMobile/Build/Build.data.unityweb"
: "Build/Build/Build.data.unityweb",
frameworkUrl: isMobile
? "BuildMobile/Build/Build.framework.js.unityweb"
: "Build/Build/Build.framework.js.unityweb",
codeUrl: isMobile
? "BuildMobile/Build/Build.wasm.unityweb"
: "Build/Build/Build.wasm.unityweb",
streamingAssetsUrl: isMobile
? "BuildMobile/StreamingAssets"
: "Build/StreamingAssets",
companyName: "Ministry of Tourism",
productName: "MOT2.0_Project",
productVersion: "1.0",
cacheControl: handleCaching,
});
Would you be interested in contributing a fix?
- yes, I would like to contribute a fix