2

I am building an HTML5 web game, a spin on the classic asteroids game to be precise. The problem I'm running into is that Safari, unlike Chrome or Firefox, will NOT automatically cache and use .wav sound files. This is causing substantial lag if there are an abundance of sounds occurring. On each instance of needing a "shooting" sound, the browser will perform a new GET request to obtain the audio file, as seen below:

Audio files Cached:No

you will see that the 151013__bubaproducer__laser-classic-shot-2.wav is the shooting sound that is being requested through the network over and over again and is not being cached. In an attempt to force Safari to cache this file, I've created an Asteroids.manifest file for the appcache to utilize:

enter image description here

Yes, that is the correct directory location relative to both the index.html as well as the Asteroids.manifest. And the manifest file does appear to be consumed, as it is visible in Safari's debugger storage:

enter image description here

Please let me know if you have any suggestions, as I've tried a variety of different setups of the .manifest file, including naming it .appcache, ensuring that it is served up with a MIME type of text/cache-manifest, and removing the NETWORK/CACHE/FALLBACK fields

Edit note: the window.applicationCache.status() is 1 (Idle)

kjbradley
  • 335
  • 2
  • 4
  • 20
  • you might be able to tweak the headers on the wav file to at least get it to cache after first play, if this question is correct: http://stackoverflow.com/questions/11094414/caching-sounds-on-mobile-safari – dandavis Jan 10 '17 at 11:26

2 Answers2

2

I think that Safari doesn't cache audio files even if listed in the manifest file. Have you tried encoding the audio as BASE64 string and decode/convert back to audio at startup? Have a look at the WepApi, it can probably help you with that process.

opp
  • 1,010
  • 10
  • 17
1

If you mean mobile, then there are some posts here: HTML5 offline video caching in mobile safari

In summary, there is an ~5mb limit for the cache in mobile Safari. There may be something similar on the desktop. Another poster said that audio & video are not cached by the iPhone since they are played by external applications. It seems the only workaround is to store them as base64 in the local database (or local storage perhaps also? - Just keep in mind that "in private" browsing disables it).

If not, perhaps something to consider if you do plan to target the mobile version.

Community
  • 1
  • 1
James Wilkins
  • 6,836
  • 3
  • 48
  • 73