当我在 Javascript 中加载相同的声音 n 次时,浏览器会只是从服务器获取声音,然后将其复制到 n 个不同的对象

When I load the same sound n times in Javascript, will the browser just get the sound from the server and then copy it to n different objects?

本文关键字:声音 对象 然后 获取 服务器 复制 浏览器 Javascript 加载 次时      更新时间:2023-09-26

我使用Javascript。例如:

sound = [];
for (var i = 0; i < 20; i ++)
    sound[i] = new Audio("source.wav");

声音实际上会从服务器检索 20 次,还是只检索一次?

具体来说,我说的是Google Chrome,Opera,Safari,Opera和IE。所有主流的,更大的,仍然活跃的浏览器。我问是因为加载同一声音的多个版本是我游戏中非常重要的一部分。

取决于浏览器。聪明的人只会使用缓存...愚蠢的人不会