Luca Holland
Luca Holland

Reputation: 21

HTML5 Audio Caching - More than Once?

I'm creating a Javascript/HTML5 Audio-driven application, that is aimed at several browsers, however it would ideally have to work on mobile browsers, too (iPhone and Android 2.1+).

There's a lot of audio in the application, but it is not all needed at the same time, therefore I don't preload the data (saves on load time, and cuts down the amount the user might have to download on their mobile).

I'm going to be using tags to set up the audio, with the corresponding s, then use a Javascript 'Audio()' object to access them. There has to be multiple sources for each file, in order to support multiple browsers.

My question is, if I use multiple Audio() objects using the same source file, but created separately, will the browser cache them separately?

e.g.

var audioObject = new Audio();
audioObject.src = document.getElementById('song').src;

Upvotes: 2

Views: 1535

Answers (1)

JCOC611
JCOC611

Reputation: 19729

That depends entirely on the browser. However, most browsers download the sound file once, and use the cache copy for the other instances. The same thing happens with images with the same source. And presumably with script files.

So for example, if you have ten Audio objects that use the same sounds/myFile.mp3 then most browsers will download the file once and assign the same cache copy to each of the objects.

Upvotes: 1

Related Questions