I am developing a game on canvas.
Of course, sounds are an important part of any game. Sometimes, however, the same sound can be played more than once at a time.
I already have a code that checks whether the desired sound is already playing, and if so, creates a new sound with the same source and plays it. (And from now on, use two sound elements in turn until it plays three times in a row, in which case it will add another sound to the list, etc.)
However, the above method causes some delay for the first time when the sound is needed more than once at a time, therefore, to facilitate this, I want to preload the same sound in anticipation of its use more than once at a time.
I set up a loop where it will add one of the preloads, then when this is done, the next one will be added, etc. This allows me to preload a bunch of sounds without interrupting other HTTP activity (which might be necessary for the game).
However, I notice that every time it outputs sound from the server, even if the sound is already loaded.
Here the headers are sent by the server:
HTTP / 1.1 200 OK
Date: Wed, Jul 24 2013 20:16:44 GMT
Server: apache / 2.2.23 (unix) mod_ssl / 2.2.23 openssl / 0.9.8e-fips-rhel5 mod_bwlimited / 1.4
Last Modified: Wed, Jul 10, 2013 12:58:44 PM GMT
ETag: "209f80-5121-4e127d668a900"
Accept-Ranges: Byte
Content Length: 20769
Cache-Control: max-age = 29030400, public Expires: Thu, Jul 24, 2014 8:16:44 PM GMT
X-UA compatible: IE = Edge
Connection: close
Content-Type: audio / mpeg
As you can see, I have a cache control header that works fine for images and scripts, but for some reason it is not used for sounds. The browser requests them again each time.
Help? = D
EDIT: Okay, now the browser seems to be using the cache for the first time the sounds are loading, but each subsequent request requests the server. Umm .....
EDIT 2: Chrome seems to handle this just fine. Internet Explorer seems to have a problem.