Coding⏱️ 3 min read📅 2026-06-03

How to Fix: "Cross origin requests are only supported for HTTP." error when loading a local file

Three.js JSONLoader issue with local file loading.

Quick Answer: Use the URL for the local file instead of a relative path, or use a different loader like GLTFLoader.

The error "Cross origin requests are only supported for HTTP" occurs when your web application attempts to load a local file using JavaScript, but the file is not accessible via HTTP due to security restrictions.

This issue affects developers and designers who work with local files in their browser, often when testing or debugging web applications.

⚠️ Common Causes

  • The primary reason for this error is that browsers enforce same-origin policy, which restricts JavaScript access to resources loaded from a different origin (domain, protocol, or port). In your case, the 3D model file is stored locally on your computer, which means it's not accessible via HTTP.
  • An alternative reason could be that the JSONLoader library used in Three.js might not properly handle local file loads. However, this is unlikely to be the cause of the error, as JSONLoader is designed to work with local files.

🔧 Proven Troubleshooting Steps

Using a Local Server

  1. Step 1: Step 1: Set up a local server on your computer using tools like Apache, IIS, or Node.js. This will allow you to serve the 3D model file via HTTP.
  2. Step 2: Step 2: Configure the Three.js application to use the local server instead of loading the file directly from the browser's file system. You can do this by setting the `url` property of the JSONLoader instance to a URL that points to the local server.
  3. Step 3: Step 3: Test your application and verify that the 3D model loads successfully.

Using a Workaround with JSONLoader

  1. Step 1: Step 1: Use the `crossOrigin` option of the JSONLoader instance to bypass the same-origin policy. Set `crossOrigin` to `true` and specify the `mode` property as `'cors'`. This will allow the loader to make cross-origin requests, but be aware that this might not work in all browsers.
  2. Step 2: Step 2: Test your application and verify that the 3D model loads successfully.

✨ Wrapping Up

To resolve the "Cross origin requests are only supported for HTTP" error when loading a local file into Three.js, you can use one of two methods. Setting up a local server or using a workaround with JSONLoader can both help bypass the same-origin policy and allow your application to load the 3D model successfully.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions