I'm loading and playing audio files using the Audio()
constructor. This works fine in most browsers, but Chrome seems to make a new GET request for the site's favicon every time .play()
is called. It looks like this happens regardless of file type, if it's a local file, same site or cross site.
It also seems to create a lot of garbage memory. Is there a way to prevent this?
Open DevTools and look at the networks tab while clicking the button in the example below.
const bounce = new Audio('https://www.w3schools.com/graphics/bounce.mp3');
function playSound() {
bounce.play();
}
document.getElementById('bounce').addEventListener('click', playSound, false);
<button id="bounce">Play</button>