- Docs
- Browser
No bundle required
Choose modules or one global.
The ESM queue has no Node imports. The classic build publishes the same queue behavior as globalThis.Queue.
Native ESM
Use the bare package name.
js-queue works with bundlers and without a bundler. Bundlers resolve bare imports normally; native browser ESM resolves them through a standard import map with no build or transpilation step.
For the normal npm layout, where easy-stack is hoisted, put this complete import map before the module script:
<script type="importmap">
{
"imports": {
"js-queue": "./node_modules/js-queue/queue.js",
"js-queue/": "./node_modules/js-queue/",
"js-queue/stack": "./node_modules/js-queue/stack.js",
"js-queue/stack.js": "./node_modules/js-queue/stack.js",
"easy-stack": "./node_modules/easy-stack/stack.js"
}
}
</script>
<script type="module">
import Queue from 'js-queue';
import Stack from 'js-queue/stack';
const queue=new Queue;
const stack=new Stack;
</script>If the application has a conflicting root easy-stack and npm nests js-queue's exact dependency, use this complete scoped map instead:
<script type="importmap">
{
"imports": {
"js-queue": "./node_modules/js-queue/queue.js",
"js-queue/": "./node_modules/js-queue/",
"js-queue/stack": "./node_modules/js-queue/stack.js",
"js-queue/stack.js": "./node_modules/js-queue/stack.js",
"easy-stack": "./node_modules/easy-stack/stack.js"
},
"scopes": {
"./node_modules/js-queue/": {
"easy-stack": "./node_modules/js-queue/node_modules/easy-stack/stack.js"
}
}
}
</script>
<script type="module">
import Stack from 'js-queue/stack';
const stack=new Stack;
</script>Node and bundlers resolve easy-stack from the importing js-queue package. The browser scope applies the same boundary instead of accidentally selecting a conflicting consumer-root copy.
Classic script
Keep the familiar global.
queue-vanilla.js is intentionally not an ES module. Load it with a normal script tag in a current browser with native private fields.
<script src='./node_modules/js-queue/queue-vanilla.js'></script>
<script>
const queue=new Queue;
queue.add(function(){
console.log('classic browser task');
this.next();
});
</script>| File | Script type | Access |
|---|---|---|
queue.js | type="module" | Default or named Queue export |
queue-vanilla.js | Classic | globalThis.Queue |
Local development
Use HTTP(S), not file://.
Every import-map path is relative to the HTML document, and the server must expose each mapped package file. Browser module security rules are designed around origins, so file:// is not supported. This repository includes a dependency-free static server for docs and examples.
npm start
# open http://127.0.0.1:8000/examples/The live example imports the exact ESM queue published by this site.
Open live example