How to delete the cache of the AUDIO TAG?

1

Dear greetings, someone knows how to erase the caching of the audio tag, with javascript.

I have the following problem.

I generate an Audio mp3 and I charge it on my AUDIO tag. but according to another event I generate another Audio with the same name, but when I play it, it follows the first audio.

The mp3 file was generated correctly. The routes are correct.

    
asked by ChiGy 04.08.2017 в 16:12
source

1 answer

0

The fast and furious way to force JavaScript not to cache an asset is modifying its URL. If you are creating your audio like this:

var audio = document.createElement('audio');
audio.src = 'tu_archivo.mp3';

You can modify it like this:

var audio = document.createElement('audio');
audio.src = 'tu_archivo.mp3?aleatorio=' + Math.random();

This forces the browser to load the file from the server each time.

    
answered by 04.08.2017 в 22:04