-
-
Notifications
You must be signed in to change notification settings - Fork 189
Description
Hi 👋
I’ve noticed a problem when importing multiple libraries through esm.sh:
• Each import URL bundles its own dependencies.
• If two or more libraries share the same dependency, the browser still downloads it multiple times.
• For small deps this is fine, but for large ones (like three
) it’s a big issue.
import * as THREE from "https://esm.sh/three";
import { OrbitControls } from "https://esm.sh/three/examples/jsm/controls/OrbitControls.js";
import { GLTFLoader } from "https://esm.sh/three/examples/jsm/loaders/GLTFLoader.js";
In this case, each addon import pulls in its own copy of three, so the browser downloads the same dependency multiple times.
I know there’s the ?external=three option to avoid bundling, but this still requires configuring every addon import manually.
Feature request
Would you consider adding a way to declare multiple npm modules in a single esm.sh URL, so esm.sh can resolve them together and avoid duplicating shared dependencies?
For example something like:
import {
OrbitControls,
GLTFLoader
} from "https://esm.sh/group?pkg=three/examples/jsm/controls/OrbitControls,three/examples/jsm/loaders/GLTFLoader&external=three";
This would make it easier to import addons/plugins that share a heavy dependency, without repeating ?external=... for every import.
Is this something you are considering, or maybe there’s already a recommended solution?
Thanks! 🙏