howler.js is a robust JavaScript audio library designed for modern web applications, abstracting away the complexities of the Web Audio API and falling back seamlessly to HTML5 Audio when necessary. Currently stable at version 2.2.4, it sees regular maintenance releases addressing browser-specific quirks and improving reliability, such as fixes for Opera versions 100+ and Chrome for iOS. Key differentiators include its single, intuitive API, comprehensive cross-browser compatibility across desktop and mobile, support for audio sprites, 3D spatial audio, and an automatic HTML5 audio node pooling system to overcome common browser autoplay restrictions. It's a dependency-free, lightweight solution, offering full control over playback features like fading, rate, seek, and volume, suitable for a wide range of audio needs from simple sound effects to complex interactive audio experiences. It prioritizes performance with automatic caching and is modular, weighing in at just 7kb gzipped.
npm install howlerVerified import paths — ran on the pinned version, not inferred.
Initializes and plays background music and a sound effect, demonstrating global mute/unmute functionality and basic playback options.
Ensure `Howl.play()` calls are triggered by a user gesture (e.g., click, keydown). Howler.js attempts to auto-unlock on the first user input, but explicit user interaction remains critical for reliable playback initiation.
Upgrade to v2.1.0 or newer. This version introduced a global pool of HTML5 Audio nodes, which are unlocked on first user input, significantly improving reliability for subsequent HTML5 audio plays.
For `Howl` instances requiring custom XHR settings, utilize the `xhr` property in the options object. This property, added in v2.2.0, allows specifying custom `headers`, `withCredentials`, and HTTP `method` for the request.
Regularly update `howler.js` to the latest version (currently 2.2.4). The library actively addresses these browser-specific issues, providing fixes for improved cross-browser compatibility and stability.
Call `sound.play()` only within an event listener for a user interaction. `howler.js` attempts to unlock audio on first input, but direct calls outside user events will fail.
For ES Modules, use `import { Howl, Howler } from 'howler';`. For CommonJS, use `const { Howl, Howler } = require('howler');`. If using a script tag, ensure `howler.js` is loaded before your script and that `Howl` is accessed globally.Update `howler.js` to version 2.2.2 or newer, which includes specific fixes for looping sounds in recent Firefox desktop versions.
When creating a new `Howl` instance for such files, set the `xhr` option with the appropriate `headers` or `withCredentials: true` property. This feature is available since `howler.js` v2.2.0.
No dependency data recorded yet.