网页底部/顶部的JavaScript? [英] JavaScript at bottom/top of web page?

查看:173
本文介绍了网页底部/顶部的JavaScript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚使用Mozilla Firefox的插件Yslow,它告诉我应该把JavaScript放在底部。我之前听过这个,但没有真正想过这个。与顶部相比,将JavaScript放在网页底部真的有优势吗?

I was just using the plugin "Yslow" for Mozilla Firefox, and it told me that I should put JavaScript at the bottom. I have heard this before but haven't really thought about it too much. Is there really an advantage in putting JavaScript at the bottom of a web page compared to the top?

推荐答案

它会允许在执行JavaScript之前可以明显加载的网页,这对于像Google Analytics这样的内容是有意义的,这些内容在页面加载之前不需要发生。

It'll allow the web page to load visibly before executing JavaScript, which makes sense for things like Google Analytics, which don't need to happen before the page loads.

您可能还想要查看jQuery,prototype等内容并附加到ready处理程序,该处理程序在DOM完全加载后执行JavaScript代码,这是适用于大量JavaScript代码的地方。

You may also want to look into things like jQuery, prototype, etc and attach to the "ready" handler, which executes JavaScript code after the DOM has been fully loaded, which is an appropriate place for much JavaScript code.

这篇关于网页底部/顶部的JavaScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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