English 中文(简体)
延迟装入 Javascript 以加速我的Joomla
原标题:Delay Loading Javascript to speed my Joomla

我使用Joomla网站, 强迫使用额外的java脚本。

我的问题是:

  1. How to force loading the javascript ONLY after page complete
  2. I dont mean DELAY them, But make them in Queue till the page complete loading.

我尝试了很多连接 辅导,但没有什么帮助我。

请,

你能否提供正确的例子,让我理解。

将JS文件我插入到我页面的 buttom 的示例 :

<script src="/js/easing.js" type="text/javascript"></script>

您能否提供 Jquery 代码, 强制所有这些脚本 等到页面加载完成?

谢谢

塔里克

最佳回答

Ales Kotnik回答得很好, 而且如果你想在你自己的精密时间里做, 你可以做这样的事情:

function loadScript(url, callback){

var script = document.createElement("script")
script.type = "text/javascript";

if (script.readyState){  //IE
    script.onreadystatechange = function(){
        if (script.readyState == "loaded" ||
                script.readyState == "complete"){
            script.onreadystatechange = null;
            callback();
        }
    };
} else {  //Others
    script.onload = function(){
        callback();
    };
}

script.src = url;
document.getElementsByTagName("head")[0].appendChild(script);
}

此操作只有在您调用脚本时才会装入脚本, 然后像这样激活它 :

<script type="text/javascript" src="http://your.cdn.com/first.js"></script>
<script type="text/javascript">
loadScript("http://your.cdn.com/second.js", function(){
    //initialization code
});
</script>
问题回答

使用 。 在现代浏览器( HTML5) 中, 它将产生单独获取 javascript 文件的产物, 并将推迟 HTML 的装入。 您可以在您的 结尾处放置脚本标记 。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签