javascript 推迟脚本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 推迟脚本相关的知识,希望对你有一定的参考价值。

// Defer Iframe Loading - move src to data-src and leave src empty
function init() {
var vidDefer = document.getElementsByTagName('iframe');
for (var i=0; i<vidDefer.length; i++) {
if(vidDefer[i].getAttribute('data-src')) {
vidDefer[i].setAttribute('src',vidDefer[i].getAttribute('data-src'));
} } }
window.onload = init;

// Defer sripts by placing their calls in an internal file
// Place this script immediately before the </body>
// Keep defer.js file in root
function downloadJSAtOnload() {
var element = document.createElement("script");
element.src = "defer.js";
document.body.appendChild(element);
}
if (window.addEventListener)
window.addEventListener("load", downloadJSAtOnload, false);
else if (window.attachEvent)
window.attachEvent("onload", downloadJSAtOnload);
else window.onload = downloadJSAtOnload;

// Defer Script Files only - requires jQuery
$(window).load(function(){
    $.getScript("//apis.google.com/js/platform.js");
    $.getScript("//platform.linkedin.com/in.js")
});

以上是关于javascript 推迟脚本的主要内容,如果未能解决你的问题,请参考以下文章

概要/笔记

概要/笔记

php 插件:推迟联系表格7脚本

python 脚本将github提交统计信息推迟

javascript jquery推迟

php 推迟解析JavaScript