您何时选择在页面底部而不是顶部加载javascript? [英] When do you choose to load your javascript at the bottom of the page instead of the top?

查看:141
本文介绍了您何时选择在页面底部而不是顶部加载javascript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到JavaScript页面正在页面的顶部和底部加载。

I have seen JavaScript libraries being loaded at the top and bottom of the page.

我很想知道何时做出这些选择。我编写的所有JavaScript代码都在页面顶部工作,其中包括jquery插件。

I would love to know when to make these choices. All the JavaScript code I've written all work at the top of the page, which includes jquery plugins.

我什么时候在这些位置上加载我的脚本?

When do i load my script at any of these positions?

推荐答案

顶部:立即对元素执行JavaScript事件功能更为重要(因此,如果使用DOM Ready事件加载所有内容,这是错误的地方)

Top: When having JavaScript events function on elements immediately is more important (so if you use a DOM Ready event to load everything, this is the wrong place)

底部:加载内容时更重要

这篇关于您何时选择在页面底部而不是顶部加载javascript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆