This is a client-side CDN fronting unpkg.com, which in turn is a CDN for npm.
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>
pm.js
creates an iframe and loads /pm/
into it.
importer()
function.
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.
pm.js
, where it gets
evaluated in a mock-Realm and resolved as the value of the promise.
Below is a preact component rendered with a copy of the library loaded from unpkg: