Search code examples
three.jswebservermicrosoft-edgemozillagltf

why does three.js loader requires webserver only for certain browsers?


After playing around a bit with three.js and the gltf loader I have noticed that Mozilla and Edge don't require the gltf file to be located in a web server, but ie11 does. Could anyone explain me why is this?

Thanks


Solution

  • This happens because of security restrictions in browsers. For example if you try load a glTF asset directly from file via the file protocol (file:///), Chrome logs the following error:

    Access to XMLHttpRequest at 'file:///...DamagedHelmet.gltf' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

    The behavior of browsers varies since they do not implement equal security policies.

    In order to avoid security related problems, three.js recommends to use a local web server when developing/testing WebGL applications that load assets from external files.