1. Docs
  2. 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>
Browser choices
FileScript typeAccess
queue.jstype="module"Default or named Queue export
queue-vanilla.jsClassicglobalThis.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