显示:无保持元素加载? [英] Does display:none keep elements from loading?
问题描述
我有一个大的视频文件,我想放在我的主页。我不想让它减少加载时间,所以我想我可以设置它显示:无,然后在页面加载后更改显示。
I have a large video file that I want to put on my main page. I don't want it to bog down the loading time, so I was thinking I could just set it to display:none and then change the display after the page loads. Would this work?
推荐答案
这会有效吗?
Would this work?
不适用。 display:none
只会阻止显示元素;它将被加载。
Nope. display: none
will only prevent the element from being displayed; it will be loaded nevertheless.
您可以在选择的元素检查器中看到这种情况(例如在Firebug或IE8的开发工具中)。
You can watch this happen in the element inspector of your choice (e.g. in Firebug or IE8's dev tools).
最好的方法可能是使用JavaScript创建视频元素,或者 - 如果你想要一个fail-safe解决方案,在JS被关闭 - 你可以使用iframe加载视频,如果用户点击一个链接。
The best way is probably to create the Video element using JavaScript afterwards, or - if you want a fail-safe solution in case JS is turned off - you could use an iframe that loads the video if the user clicks a link.
这篇关于显示:无保持元素加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!