user2059509
user2059509

Reputation: 73

<audio> and javascript: can I force audio files to be redownloaded each time they're used?

I'm developing an audio captcha system. My problem is that when the audio file containing the numbers which the user must type is updated on the server, the browser doesn't refresh it. Instead, it plays the old, invalid audio until the browser is closed down. How can I make the element rebuffer the audio each time load and play are called instead of playing stored versions? Thanks.

Upvotes: 1

Views: 244

Answers (1)

Dragos
Dragos

Reputation: 508

Browsers generally enjoy caching elements they are sent with exactly the same file name. Normally the best way to avoid this in javascript is to add a function that adds some useless random string to the resource. For example audioNotToBeCached.snd?1421124sjam2

The random string after the question mark is ignored and the browser can't cache based on filenames any more.

Plenty of options here.

Upvotes: 2

Related Questions