是“将脚本置于底部”正确? [英] Is "Put Scripts at the Bottom" Correct?

查看:180
本文介绍了是“将脚本置于底部”正确?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在改善网站效果的最佳做法中 http://developer.yahoo.com/performance /rules.html ,Steve Souders提到了一条规则将脚本移到底部。这有点令人困惑。实际上,我注意到很多网页都没有把脚本放在底部,而 YSlow 仍在标记A这些页面。

In the Best Practices to improve web site Performance http://developer.yahoo.com/performance/rules.html, Steve Souders mentioned one rule "Move Scripts to the Bottom". It's a little confusing. Actually, I notice that a lot of web pages that doesn't put script at bottom, while YSlow still mark A for these pages.

那么,我应该何时遵循将脚本置于底部这一规则?

So, when should I follow the rule "Put Scripts at the Bottom"?

推荐答案

当用户从您的站点请求页面时,页面HTML开始流式传输到浏览器。一旦浏览器遇到外部图像,脚本,CSS文件等的标记,它将立即开始同时下载该文件。

When a user requests a page from your site, the page HTML starts streaming to the browser. As soon as a browser encounters a tag for an external image, script, CSS file, etc., it will start downloading that file simultaneously.

如果您将脚本放在页面底部,它们将被最后加载。换句话说,您将首先加载您的页面/应用程序的HTML内容/结构/ css /图像,并且可以更快地在浏览器中显示某些内容;您的用户在看到应用程序中的内容之前不必等待脚本完成下载。

If you put your scripts at the bottom of a page, they'll be loaded last. In other words, the HTML content/structure/css/images of youe page/app will be loaded first, and something can show up in the browser faster; Your users don't have to wait for a script to finish downloading before they see something in your application.

这篇关于是“将脚本置于底部”正确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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