你怎么总是刷新html音频

How do you always refresh html Audio

我的网络应用程序基于生成和播放音频文件。不幸的是,尽管音频文件本身正在更新(我知道这一点是因为当我下载它时它是正确的),但网站上播放的音频是缓存的旧版本。即使多次硬刷新也不会通过缓存。如何重新加载音频源。

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

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)

这些不是同一个 HTTP 请求。当您使用 <audio> 元素时,它会发出远程请求。沿途某处的某些东西正在缓存它。

无论如何,您需要做的就是在 HTTP 响应上设置适当的 Cache-Control header。这样的事情会做:

Cache-Control: no-store

(当然,您实际上需要刷新浏览器的缓存,以及任何 server-side 缓存,然后您才能看到它生效。)

另请参阅:https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control