How can I get a json file hosted on the IC with JS in the browser? [Anonymous Dev Question]

My Intent

Ahoy ICP devs!

Within the internal DFINITY team channels (OpenChat, Signal, Slack), I have seen some developer-centric technical questions which I think would be great for the wider developer forum to see. I think they can be helpful to share the question/answer so future folks looking for answers can find them.

This is my first attempt at doing this, and if people do not find it useful, I will stop :slight_smile:

Let me know what you think. Thanks!


How can I get a json file hosted on the IC with JS in the browser?

fetch isn’t working because I get CORS issues. Can they be set in the canister? Or should I use agent-js somehow? I believe it’s a normal CORS issue, but with IC maybe I’m missing something :sweat_smile:



you can configure the asset canister to return custom headers, i.e., you can configure

*Access-Control-Allow-Origin: **

there and you should be able to fetch it from a different origin.


Configure it where? I didn’t know there was a config file for the standard Asset canister.



Ideally everyone asks all technical questions in the open forum, so that their answers are also searchable and in the open forum.

Anonymous posting can probably be enabled if necessary.

I agree.

I do think its reasonable people post things in internal channels because they expect faster reply, but I think moving more and more openly is good.

To be honest, I anonymized the question for non-obvious reason:

  1. I removed information about the problem that I thought the original author may not want in a public format.

  2. I anomymized also because I see a whole lot of internal slack questions which i think would help to be public, and anomyzing would make it easier to get the blessing to post it. I want to do LOTS more.

1 Like