AI TOOLS

Load a JSON or CSV file in a shared HTML page

A page that loads data.json or data.csv with fetch() works in the AI chat preview and shows nothing once you open or share it. Why the request fails, and two ways to make the data load for everyone: put it in the page, or host the file in Media.

4 min read·

Claude, ChatGPT and Gemini often split a page into index.html plus a data file, and load it with fetch("data.json").then(r => r.json()) or fetch("data.csv"). The chat preview has both files, so the page fills in.

Saved to your computer and double-clicked, the page stays empty. Uploaded on its own, it stays empty for every viewer. Two separate causes, one per case.

Why it fails

Opened from disk, the page has a file:// address and Chrome blocks fetch() from reading other files. Tested in headless Chrome: fetch("data.json") from a file:// page rejected with "TypeError: Failed to fetch".

Once shared, the link serves the HTML file you uploaded. data.json is still on your computer, so the request returns 404 and the page has no data.

A third case: the data sits on another server that does not send an Access-Control-Allow-Origin header. Tested: the same fetch() from a hosted page to a second origin failed without the header and returned the data with it. Raw links from cloud drives and personal sites often lack the header.

Fix 1: put the data in the page

For data up to a few megabytes, move it into the HTML file so there is nothing to fetch. Ask the AI tool to "inline data.json into the page and remove the fetch", or do it by hand:

  • ✓<script type="application/json" id="data"> followed by the contents of data.json, then </script>. The browser does not run a script block with this type.
  • ✓const data = JSON.parse(document.getElementById("data").textContent);
  • ✓Replace the fetch(...).then(r => r.json()) chain with that line and pass data on as before.
  • ✓For CSV, the same pattern with PapaParse: a dashboard that reads a CSV file.

Fix 2: upload the data file to Media

For a large dataset, or one file used by several pages, keep the data separate. In the FileShare Pro app open Media, drop data.json in, and use Copy URL. Replace "data.json" in the fetch() call with that URL.

Media sends Access-Control-Allow-Origin: * on every file, so a shared page on any domain can read it with fetch(). JSON is served as application/json. A CSV is served as a download type, which fetch() reads as text all the same; tested in Chrome with both file types from a server sending the same headers.

Media files are fixed: uploading a new version gives it a new URL. To change the data, upload the new file, put the new URL in the page and upload the HTML over the old file; the page link stays the same: updating a shared link without changing it.

Media files count toward your storage (1 GB on Free) and do not count as pages.

Upload the page and send the link

Drag the HTML file onto the dashboard and copy the link. Viewers need no account. Turn on comments and they can pin questions to a chart or a row after typing a name: letting people comment on a web page.

Related: a custom font in a shared page, making an HTML file self-contained and why a page that works in chat breaks when hosted.

Frequently asked

Does a password on the page protect the data file?

No. The password protects the page. A Media URL opens for anyone who has it, and inlined data is visible in the page source to anyone who can open the page. Keep private data out of both: password-protecting an HTML page.

Can I test the fetch version on my computer?

Yes, from a local web server instead of a double-click: run python3 -m http.server in the folder and open http://localhost:8000. fetch() of a file in the same folder then works.

Got a page to share?

Drop the file, copy the link — live in seconds, free plan included.

Start sharing free