将jQuery移动到body标记的末尾

将jQuery移动到body标记的末尾

本文介绍了将jQuery移动到body标记的末尾?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的朋友阅读了一篇文章,其中提到将所有JavaScript文件移至结束正文标记的末尾(< / body> ),将改善其性能网页。

My friend read an article which mentioned that moving all JavaScript files to the end of the closing body tag (</body>), will improve the performance of a web page.

我已将所有JS文件移到最后,除了JQuery和JS文件,它们将事件附加到页面上的元素,如下所示;

I have moved all JS files to the end except the JQuery and the JS files which are attaching event to an element on page, like below;

$(document).ready(function(){
    //submit data
    $("#create_video").click(function(){ //... });
});

但他说要将jQuery库文件移到body标签的末尾。

but he's saying to move the jQuery library file to the end of body tag.

我不认为这是可能的,因为我使用jQuery选择器将许多事件附加到加载的页面元素,并且要使用jQuery选择器,必须加载jQuery库首先。

I don't think it is possible, because I am attaching many events to page elements on load using jQuery selectors, and to use jQuery selectors it is must to load jQuery library first.

是否可以在关闭body标签之前将JQuery库文件移动到页面末尾(< / body> )??

Is it possible to move JQuery library file to the end of page right before closing body tag (</body>) ??

谢谢

推荐答案

$(document).ready 函数说在DOM完成实例化之前不会运行 - 所以只要首先加载JQuery库,就可以将它移到body之后。非常规和一些假设可能不再正确,但没关系。

The $(document).ready function says not to run until the DOM has finished being instantiated - so moving it to after body is okay so long as the JQuery library is loaded first. Unconventional and some assumptions may not be correct anymore but okay.

这篇关于将jQuery移动到body标记的末尾?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 08:28