减小页面的大小能够通过排除不必要空格，注释，动态内嵌脚本，和放入外部文件的 CSS 等在页面结构中很小的改变都能够提高下载性能。
Depending upon a browser's Cache settings, it may send an
By reducing the number of files referenced in a web page, you reduce the time required for these requests to be sent and their responses to be received.
Reduce domain lookups
This may not always be practical; however, you should always be careful to only use the minimum number of different domains in your pages as possible.
Cache reused content
Make sure that any content that can be cached is cached with appropriate expiration times.
In particular pay attention to the
Last-Modified header. It allows for efficient caching of pages; by means of this header, information is conveyed to the user agent as to when the file it wants to load has last been modified. For static pages (e.g. <tt>.html</tt>, <tt>.css</tt>), most web servers will already automatically append the
Last-Modified header, based on the last modified date stored in the file system. For dynamic pages (e.g. <tt>.php</tt>, <tt>.aspx</tt>), this of course can't be done, and the header is not sent.
So, in particular for pages which are generated dynamically, a little research on this subject is beneficial. It can be somewhat involved, but it will save a lot of page requests on pages which would normally not be cacheable.
Optimally order the components of the page
Download page content first so the user gets the quickest apparent response for page loading.
Reduce the number of inline scripts
Inline scripts can be expensive for page loading since the parser must assume that an inline script can modify the page structure. Reducing the use of inline scripts in general, and reducing the use of
document.write() to output content in particular can improve overall page loading. Use modern W3C DOM methods to manipulate page content for modern browsers rather than the older approaches based on
Use modern CSS and valid markup
Use of modern CSS reduces the amount of markup, can reduce the need for images in terms of layout, and can in many ways replace images which are actually only images of text and cost much more than the equivalent CSS and text.
Using valid markup has other advantages. Not only do browsers not have to perform "error correction" when parsing the HTML, valid markup allows free use of other tools which can pre-process your web pages. For example, HTML Tidy can remove whitespace and remove optional ending tags, however, it will refuse to run on a page with serious markup errors.
Chunk your content
Either replace table-based layout with
<div> blocks or break tables into smaller tables that can be displayed without having to download the entire page contents.
Rather than deeply nesting tables as in:
<TABLE> <TABLE> <TABLE> ... </TABLE> </TABLE> </TABLE>
use unnested tables or divs as in
<TABLE>...</TABLE> <TABLE>...</TABLE> <TABLE>...</TABLE>
Specify sizes for images and tables
If the browser can immediately determine the height and/or width of your images and tables, it will be able to display a web page without having to reflow the content. This not only speeds the display of the page but prevent annoying changes in a page's layout when the page completes loading.
Images should have
Tables should use the CSS rule
table-layout: fixed and specify widths of columns using
Choose your user agent requirements wisely
To achieve the greatest improvements in page design make sure that reasonable user agent requirements are specified for projects. Do not require your content to appear pixel-perfect in all browsers, especially not in downlevel browsers.
Ideally, your basic minimum requirements should be based upon modern browsers which support the relevant standards. This can include: Netscape 7/Gecko 1.0.2+ on any platform, Internet Explorer 5.5+ on Windows, Opera 7+ on Windows, and Safari on Mac OS X.
Note however that many of the tips listed in this Technote are common sense techniques which apply to any user agent and can be applied to any web page regardless of browser support requirements.
Example page structure
CSS files required for page appearance. Minimize the number of files for performance while keeping unrelated CSS in separate files for maintenance.
- · User visible page content in small chunks (tables / divs) that can be displayed without waiting for the full page to download.
Any scripts which will be used to perform DHTML. DHTML script typically can only run after the page has completely loaded and all necessary objects have been initialized. There is no need to load these scripts before the page content. That only slows down the initial appearance of the page load.
- If any images are used for rollover effects, you should preload them here after the page content has downloaded.
- 作者：Bob Clary, Technology Evangelist, Netscape Communications
- 最后更新：Published 2003年4月4日
- 版权信息：Copyright © 2001-2003 Netscape. All rights reserved.
- 注意：This reprinted article was originally part of the DevEdge site.