Hi there!

This is a client-side CDN fronting unpkg.com, which in turn is a CDN for npm.

Usage

The pm.js script defines a global importer() function, which returns a Promise that resolves to a module fetched and instantiated from unpkg. Any non-relative module identifiers are supported.

<script src="https://client-rocks.glitch.me/pm.js"></script>
<script>
  importer('preact').then( preact => {
    console.log(preact)
  })
</script>
    

How it Works

  1. pm.js creates an iframe and loads /pm/ into it.
  2. The script defines a global importer() function.
  3. Calls to importer() are first handled by a simple module registry, and any not-yet-loaded modules are requested from the iframe via JSON-RPC over postMessage.
  4. The iframe resolves and fetches the requested module from unpkg.com.
  5. Inside the frame, code from unpkg is transformed to CommonJS and cached permanently using its versioned identifier.
  6. The transformed source is passed back to pm.js, where it gets evaluated in a mock-Realm and resolved as the value of the promise.

Demo

Below is a preact component rendered with a copy of the library loaded from unpkg: