HPWS 5

by Yan Sheng

Rule 5: Put Stylesheets at the Top Rule 6: Put Scripts at the Bottom 这两条比较简单, 就是将, 将样式放在页面的顶部, 而脚本放在页面的底部.

一些原因:

  1. 页面各部分的下载顺序, 一般情况下是按照他们在文档中的出现顺序的.
  2. 最好能让浏览器尽快的显示内容. This is especially important for pages with a lot of content and for users on slower Internet connections. When the browser loads the page progressively, the header, the navigation bar, the logo at the top, etc. all serve an visual feedback for the user who is waiting for the page.
  3. Rule 5 has less to do with the actual time to load the page's components and more to do with how the browser reacts to the order of those components. The browser delays showing any visible components while it and the user wait for the stylesheet at the bottom.----"blank white screen."

例子:

<style>
@import url("style.css");
</style>

另外, Flash of Unstyled Content

例子:

解决这两个问题的rule就是: Put your stylesheets in the document HEAD using the LINK tag.

对于Scripts, 先看例子

But,,,,The DEFER attribute for scripts doesn't solve the issues. In Firefox, rendering and downloads are still blocked. In IE, the script is still downloaded, taking up one of the two download slots for that hostname.

虽然最后一种情况比较特殊外, 总得来说,,Move scripts to the bottom of the page

Javascriptnote