Skip to content

Multiple esm.sh imports duplicate large dependencies (e.g. three), feature request: grouped external/shared modules #1198

@vladkrutenyuk

Description

@vladkrutenyuk

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! 🙏

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions