I made a webpage for Thai alphabet learning and I want to voice over letters and sounds. Clicking on these tiles plays a really short mp3 file and there is about 200 things to click and listen which is 1mb in total.
I have difficulties:
- Preload all the mp3 files in the background.
- Download 1 file instead of 200.
- Delays in desktop safari when running audio, even for already played and cached files.
- Extreme delays in mobile browsers. Sometimes audio don't even play.
To play audio I tried something like this:
const audio = new Audio('path/to/audio.mp3');
audio.play();
...
And to let browser cache files I tried to address each one like so:
playlist.forEach(function(item) {
fetch('path/to/audio.mp3');
...
});
But this is just a draft. What will be the best approach to code it? Where do I look to improve it? Can I create an mp3 sprite? Or could it be <audio> tag with inlined base64 with preload attribute? Or maybe I could try <link rel="preload"> for some kind of mp3 sprite? Can I rely on browser's cache or I should try JavaScript library to control all the media manually? Will it works without delay if I store these files in local storage?
