[英]How do I get my webpage to load quickly when I need lots of sound files?
I'm pretty new to web design and I'm building a webpage for learning the Cherokee syllabary.我对网页设计很陌生,我正在构建一个网页来学习切诺基音节。 The main page is a table of 85 characters that plays the sound for the character when you click on one.主页是一个包含 85 个字符的表格,当您单击一个字符时,它会为该字符播放声音。 Currently I have all of the sound files stored in both .mp3 and .oog formats in a /sounds folder, and I put 85 different <audio>
tags at the end of my html document, and play them using jQuery as shown below.目前,我将所有声音文件以 .mp3 和 .oog 格式存储在 /sounds 文件夹中,我在 html 文档的末尾放置了 85 个不同的<audio>
标签,并使用 jQuery 播放它们,如下所示。 The page load time is okay on my laptop but on my phone it's really slow, and I assume this is because of all of the sound files.页面加载时间在我的笔记本电脑上还可以,但在我的手机上它真的很慢,我认为这是因为所有的声音文件。 How can I implement this in a way that loads the page more quickly?如何以更快地加载页面的方式实现这一点?
$('td').click(function(){ var name = $(this).find('.tbl-en').html(); var tag = 'audio-' + name; var sound = document.getElementById(tag); sound.play(); });
<audio id="audio-a"> <source src="sounds/a.mp3" type="audio/mp3"> <source src="sounds/a.oog" type="audio/oog"> </audio>
Don't set the src
attribute until the user has clicked on that element.在用户单击该元素之前不要设置src
属性。 Here is an example:下面是一个例子:
http://codepen.io/tevko/pen/raQMjP http://codepen.io/tevko/pen/raQMjP
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.