Importing from cdn

how to import GLTFL loader when using 3js over cdn
this is the code to import it from local files
import { GLTFLoader } from ‘three/addons/loaders/GLTFLoader.js’;

You can use this URL to load it:

https://unpkg.com/three@0.154.0/examples/jsm/loaders/GLTFLoader.js

You can substitute the version number with whichever version of ThreeJs you’re using.

so in code:

<script src="https://unpkg.com/three@0.154.0/examples/jsm/loaders/GLTFLoader.js"></script>

Alternatively, this link should give you the latest version at all times:

https://cdn.jsdelivr.net/gh/mrdoob/three.js@master/examples/jsm/loaders/GLTFLoader.js

If you want to use this exactly string:

Define import map that maps three/addons/
to https://unpkg.com/three@0.154.0/examples/jsm/

Like in this template https://codepen.io/boytchev/pen/QWZQKEB?editors=1011 (you can use other CDN’s URLs if you like)

<script async src="https://ga.jspm.io/npm:es-module-shims@1.5.1/dist/es-module-shims.js" crossorigin="anonymous"></script>
<script type="importmap">
  {
    "imports": {
      "three": "https://unpkg.com/three@0.154.0/build/three.module.js",
      "three/addons/": "https://unpkg.com/three@0.154.0/examples/jsm/"
    }
  }
</script>
2 Likes