Rule 5: Put Stylesheets at the Top(Chapter 5 of High performance Web Sites)
2009-10-12 23:00
951 查看
Frontend engineers who care about performance want a page to load progressively;
that is, we want the browser to display whatever content it has as soon as possible.
This is especially important for pages with a lot of content and for users on slower
Internet connections.The importance of giving users visual feedback has been well
researched and documented.
Here are the cases where putting stylesheets at the bottom of the document causes
the blank white screen problem to surface in Internet Explorer:
In a new window
Clicking the “new window” link in the example page opens “CSS at the Bottom”
in a new window.Users often open new windows when navigating across
sites, such as when going from a search results page to the actual target page.
As a reload
Clicking the Refresh button, a normal user behavior, is another way to trigger a
blank white screen.Minimize and restore the window while the page is loading
to see the blank white screen.
As a home page
Setting the browser’s default page to http://stevesouders.com/hpws/css-bottom.php
and opening a new browser window causes the blank white screen.Rule 5 is
important for any team that wants its web site to be used as a home page.
To avoid the blank white screen, move the stylesheet to the top in the document’s
HEAD.Doing this in the sample web site I’ve called “CSS at the Top” solves all the
problem scenarios.No matter how the page is loaded—whether in a new window, as
a reload, or as a home page—the page renders progressively.
There are two ways you can include a stylesheet in your document: the LINK tag and
the @import rule. An example LINK tag looks like this:
<link rel="stylesheet" href="styles1.css">
This is an example of a STYLE block with an @import rule:
<style>
@import url("styles2.css");
</style>
that is, we want the browser to display whatever content it has as soon as possible.
This is especially important for pages with a lot of content and for users on slower
Internet connections.The importance of giving users visual feedback has been well
researched and documented.
Here are the cases where putting stylesheets at the bottom of the document causes
the blank white screen problem to surface in Internet Explorer:
In a new window
Clicking the “new window” link in the example page opens “CSS at the Bottom”
in a new window.Users often open new windows when navigating across
sites, such as when going from a search results page to the actual target page.
As a reload
Clicking the Refresh button, a normal user behavior, is another way to trigger a
blank white screen.Minimize and restore the window while the page is loading
to see the blank white screen.
As a home page
Setting the browser’s default page to http://stevesouders.com/hpws/css-bottom.php
and opening a new browser window causes the blank white screen.Rule 5 is
important for any team that wants its web site to be used as a home page.
To avoid the blank white screen, move the stylesheet to the top in the document’s
HEAD.Doing this in the sample web site I’ve called “CSS at the Top” solves all the
problem scenarios.No matter how the page is loaded—whether in a new window, as
a reload, or as a home page—the page renders progressively.
There are two ways you can include a stylesheet in your document: the LINK tag and
the @import rule. An example LINK tag looks like this:
<link rel="stylesheet" href="styles1.css">
This is an example of a STYLE block with an @import rule:
<style>
@import url("styles2.css");
</style>
相关文章推荐
- Rule 6: Put Scripts at the Bottom(Chapter 6 of High performance Web Sites)
- Rule 14: Make Ajax Cacheable(Chapter 14 of High performance Web Sites)
- Rule 9: Reduce DNS Lookups(Chapter 9 of High performance Web Sites)
- The Importance of Frontend Performance(Chapter A of High performance Web Sites)
- Rule 3: Add an Expires Header(Chapter 3 of High performance Web Sites)
- Rule 11: Avoid Redirects(Chapter 11 of High performance Web Sites)
- Rule 8: Make JavaScript and CSS External(Chapter 8 of High performance Web Sites)
- Rule 10: Minify JavaScript(Chapter 10 of High performance Web Sites)
- Rule 4: Gzip Components(Chapter 4 of High performance Web Sites)
- Rule 1: Make Fewer HTTP Requests(Chapter 1 of High performance Web Sites)
- Rule 12: Remove Duplicate Scripts(Chapter 12 of High performance Web Sites)
- Rule 13: Configure ETags13(Chapter 13 of High performance Web Sites)
- Rule 7: Avoid CSS Expressions7(Chapter 7 of High performance Web Sites)
- Rule 2: Use a Content Delivery Network(Chapter 2 of High performance Web Sites)
- 构建高性能网站的14条法则:Put Stylesheets at the Top
- HTTP Overview(Chapter B of High performance Web Sites)
- Why is there extra padding at the top of my UITableView with style UITableViewStyleGrouped in iOS7
- High Performance Web Sites: Rule 13 – Configure ETags
- PROGRAMMING THE WORLD WIDE WEB Chapter 3 Cascading Style Sheets
- how to move a rule to the top position at rule list?