Joshua Segal
Joshua Segal

Reputation: 583

How do you always refresh html Audio

My web application is based on generating and playing an audio file. Unfortunately, despite the audio file itself being updated (I know this because when I download it it's correct), the audio that is played on the website is a cached, old version. Even hard refreshing multiple times doesn't get past the cache. How can I reload the audio source.

<audio controls>
    <source src="/static/output.wav">
</audio>

Upvotes: 0

Views: 608

Answers (1)

Brad
Brad

Reputation: 163438

Even hard refreshing multiple times doesn't get past the cache.

...

Unfortunately, despite the audio file itself being updated (I know this because when I download it it's correct)

Those aren't the same HTTP request. When you use the <audio> element, it will make ranged requests. Something, somewhere along the way, is caching it.

In any case, all you need to do is set the appropriate Cache-Control header on the HTTP response. Something like this will do:

Cache-Control: no-store

(Of course, you will actually need to flush your browser's cache, and any server-side caches before you'll see this take effect.)

See also: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control

Upvotes: 1

Related Questions