Adding files for LivePreview

I'm developing a game that requires a .json file with static data. I've added data.json to my Hype Resources, and it appears there as a regular file. However, when I try to locate this file in the browser (F12 -> Sources -> index.hyperesources) during live preview, it's not present. Is there a way to ensure this file is accessible on the live preview server?

To load it with a JavaScript function, you would use this magic variable:

${resourcesFolderName}/data.json

Items you add to your resource library are exported during export but won't automatically load in the browser unless they are referenced.

Can you help me with that, how exactly i should reference it, as not it's 404.
test_json.zip (15,6 КБ)

You have two issues.

  1. You are requesting "assets.json" but the file name is "asset.json"
  2. You are using async/await in a non-async function. This causes an error. Instead you can wrap the fetch code in an async function that is fired immediately (just note that it will not be complete if you put any code after it.

The new code would look like:

  var requestURL =
    "${resourcesFolderName}/asset.json";
  var request = new Request(requestURL);

  (async function () {
	  var response = await fetch(request);
	  hypeDocument.customData.assets = await response.json();
  })();

Thanks, that works!