整理出来的tip

减小页面的大小

在页面下载中,页面的大小至今扮演着非常重要的因素。

减小页面的大小能够通过排除不必要空格,注释,动态内嵌脚本,和放入外部文件的 CSS 等在页面结构中很小的改变都能够提高下载性能。

诸如HTML Tidy这类的工具可以从有效的HTML源文件中自动截去行首空格和额外的空行,其它工具则可以通过重新格式化源代码来压缩JavaScript或者通过混淆源码将长标识符替换为短标识符来减小文件大小。

最小化文件数量

减少一个页面引用的文件数量可以降低在下载一个页面的过程中需要的HTTP请求数量。

Depending upon a browser's Cache settings, it may send an If-Modified-Since request to the web server for each CSS, JavaScript or image file, asking if the file has been modified since the last time it was downloaded.

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.

Too much time spent querying the last modified time for referenced files can delay the initial display of a web page since the browser must check the modification time for each CSS or JavaScript file before rendering the page.

减少域名查找

Since each separate domain costs time in a DNS lookup, reducing the number of separate domains used to reference CSS, JavaScript and images reduces page load times.

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.

缓存重用的内容

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. .html, .css), 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. .php, .aspx), 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.

More information:

  1. HTTP Conditional Get for RSS Hackers
  2. HTTP 304: Not Modified
  3. On HTTP Last-Modified and ETag

高效地排列页面组件

Download page content first so the user gets the quickest apparent response for page loading.

The content of the page along with any CSS or JavaScript required for its initial display should be downloaded first. This content is typically text and can benefit from text compression in the modem thus providing a quick response to the user.

Any DHTML features that require the page to complete loading before being used should be initially disabled and only enabled after the page loads. This will allow the DHTML JavaScript to be loaded after the page contents thus improving the overall appearance of the page load.

减少内联脚本的数量

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 document.write().

使用现代CSS和合法标记

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 canpre-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.

给内容分块

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:

指定图像和表格的大小

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 height and width specified.

Tables should use the CSS rule table-layout: fixed and specify widths of columns using COL and COLGROUP tags.

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.

如何制作快速加载的HTML页面的更多相关文章

  1. Ionic页面加载前 ionic页面加载完成 ionic页面销毁执行的事件

    ionic 中$ionicView.beforeEnter(页面刚加载前)  $ionicView.afterEnter  (页面加载完成) $destroy(页面销毁) 广播事件 //ionic c ...

  2. jQuery加载一个html页面到指定的div里

    一.jQuery加载一个html页面到指定的div里 把a.html里面的某一部份的内容加载到b.html的一个div里.比如:加载a.html里面的<div id=“row"> ...

  3. 用css3制作旋转加载动画的几种方法

    以WebKit为核心的浏览器,例如Safari和Chrome,对html5有着很好的支持,在移动平台中这两个浏览器对应的就是IOS和Android.最近在开发一个移动平台的web app,那么就有机会 ...

  4. Anaconda快速加载opencv

    刚刚发现了两种Anaconda快速加载opencv的方法,亲测有效: 第一种: 直接在Navigator Environment 中搜opencv 如果搜不到,登陆Anaconda Cloud官网 h ...

  5. easyui学习笔记8—在手风琴中加载其他的页面

    在手风琴中加载其他页面和在表格中加载其他的页面有写类似的,就是请求另外一个页面显示数据. 1.先看看引用的资源文件 <link rel="stylesheet" href=& ...

  6. easyui学习笔记5—panel加载其他的页面

    上一篇中我们看到了panel的基本实现,没有什么难度,最重要的是data-options和class两个标签属性的定义.这里我们将看一下在panel中如何加载其他的页面. 1.先看看引用的资源文件和h ...

  7. angularJs-未加载完成的页面显示混乱ng-bind

    ng-bind 未初始化完成不加载数据,避免产生{{}}导致页面混乱 还是上边的例子,当前页面没有加载完成的时候,页面显示是不完整的会频繁的出现{{}}这样子的表达式语句,给用户的感觉很不和谐,所以使 ...

  8. 在NVIDIA A100 GPU中使用DALI和新的硬件JPEG解码器快速加载数据

    在NVIDIA A100 GPU中使用DALI和新的硬件JPEG解码器快速加载数据 如今,最流行的拍照设备智能手机可以捕获高达4K UHD的图像(3840×2160图像),原始数据超过25 MB.即使 ...

  9. 使用Huggingface在矩池云快速加载预训练模型和数据集

    作为NLP领域的著名框架,Huggingface(HF)为社区提供了众多好用的预训练模型和数据集.本文介绍了如何在矩池云使用Huggingface快速加载预训练模型和数据集. 1.环境 HF支持Pyt ...

随机推荐

  1. iOS开发者证书申请过程

    真机测试前准备工作:1.苹果的MAC一台.如果你用的是***不知道可不可以,反正我没用过...一般公司都会给你配开发工具的.2.iphone手机一部.(本人纯屌丝,用的iphone4)3.开发者账号. ...

  2. MYSQL数据库日志和mysqlbinlog相关

    mysql有4种不同的日志,分别是二进制日志,查询日志,慢查询日志和错误日志,这些日记记录着数据库工作的方方面面,可以帮助我们了解数据库的不同方面的踪迹,下面介绍二进制日志的作用和使用方法. 1.二进 ...

  3. C#获取实体类属性名称

    方法: public static string GetPropertyName(Expression<Func<SupplierInfos, string>> expr) { ...

  4. SpringMVC RequestMapping & 请求参数

    SpringMVC 概述 Spring 为展现层提供的基于 MVC 设计理念的优秀的Web 框架,是目前最主流的 MVC 框架之一 Spring3.0 后全面超越 Struts2,成为最优秀的 MVC ...

  5. [翻译]PYTHON中如何使用*ARGS和**KWARGS

    [翻译]Python中如何使用*args和**kwargs 函数定义 函数调用 不知道有没有人翻译了,看到了,很短,顺手一翻 原文地址 入口 或者可以叫做,在Python中如何使用可变长参数列表 函数 ...

  6. Xcode真机调试报错(证书的签发者无效)

    Xcode真机调试时报错: dyld: Library not loaded: @rpath/libswiftAVFoundation.dylib Referenced from: /var/mobi ...

  7. extern引发的闹剧

    最近一个朋友让我帮他解决一个问题,由于源代码不方便贴出来,所以就自己写了个demo把问题重现一次 1.新建一个application,添加一个继承于NSObject的类 本来是随便写的,就将此类命名为 ...

  8. 使用 VS2005 通过按钮自动上传文件到Linux

    首先去官网下载 winscp,官网地址:http://winscp.net/eng/download.php 因为我这里是做自动上传工具,所以我只下载了精简版的:Portable executable ...

  9. c++ 之 编译期多态&运行期多态

    编译时多态:程序运行前发生的事件 —— 函数重载.运算符重载 .模板  ——静态绑定 运行时多态:程序运行时发生的事件 —— 虚函数机制——动态绑定 template<typename T> ...

  10. mvc 传递匿名对象

    Controller代码: public ActionResult TupleTest() { LinqDBEntities db = new LinqDBEntities(); dynamic da ...