- 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
Import the source directly.
Serve the files over HTTP and load the checked-in module with type="module". A bundler is optional, not required.
<script type="module">
import Queue from './node_modules/js-queue/queue.js';
const queue=new Queue;
queue.add(function(){
document.body.dataset.ready='true';
this.next();
});
</script>Package-name imports need a resolver.
Inside a browser, use a relative file URL as above, an import map, or the package support built into your existing bundler.
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, not file:.
Browser module security rules are designed around origins. 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