[英]How can I reuse the audio a browser already downloaded so it doesn't download it again in other pages that use the same audio file?
I'm making an audio heavy page. 我正在制作音频沉重的页面。 I'm using the JavaScript audio element.
我正在使用JavaScript音频元素。 The code looks like this:
代码如下:
JavaScript: JavaScript的:
var x = new Audio("x.mp3");
var y = new Audio("y.mp3");
var z = new Audio("z.mp3");
function playMe(n){
n.play();
}
HTML: HTML:
<button class="button" onclick="playMe(x)")>Play</button>
<button class="button" onclick="playMe(y)")>Play</button>
<button class="button" onclick="playMe(z)")>Play</button>
Some pages use up to 30 different audio files so this will consume a lot of bandwith. 某些页面最多使用30个不同的音频文件,因此会消耗很多带宽。 This can potentially kill the project, as it's a one-man effort with almost no budget.
这可能会扼杀该项目,因为这是一项几乎没有预算的单人工作。
The audios are being downloaded each time the audio object is declared. 每次声明音频对象时都会下载音频。 Is there a way to reuse the audio that was already downloaded in other pages to be used on other pages without downloading it again?
有没有一种方法可以重用已经在其他页面上下载的音频,以便在其他页面上使用而无需再次下载?
Thanks for your time. 谢谢你的时间。
You can use the Cache manifest to make sure that every resource that you want is downloaded only once and cached properly, even for offline browsing. 您可以使用“ 缓存”清单来确保所需的每个资源仅下载一次并正确缓存,甚至用于脱机浏览。 See: "Offline": What does it mean and why should I care?
请参阅: “离线”:这是什么意思,我为什么要关心? on HTML5Rocks.
在HTML5Rocks上。
Another thing that you can use instead of (or in addition to) proper caching is having your page don't really reload but having only parts of it reloaded using AJAX like in this simple demo . 除了适当的缓存之外(或除了适当的缓存之外),您还可以使用另一件事,就是不真正地重新加载页面,而是像这个简单的演示中那样使用AJAX重新加载页面的一部分。 A lot of JavaScript frameworks, like jQuery, YUI, Prototype, Dojo, etc. will help you with that.
许多JavaScript框架(例如jQuery,YUI,Prototype,Dojo等)将为您提供帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.