Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not downloading from cache - Load times super slow #552

Open
2 tasks done
samijoehayek opened this issue Apr 25, 2024 · 0 comments
Open
2 tasks done

Not downloading from cache - Load times super slow #552

samijoehayek opened this issue Apr 25, 2024 · 0 comments
Assignees
Labels

Comments

@samijoehayek
Copy link

Please avoid duplicates

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants