pagespeed 摘要 - Minimize payload size

Enable compression

Note that gzipping is only beneficial for larger resources. Due to the overhead and latency of compression and decompression, you should only gzip files above acertain size threshold; we recommend a minimum range between 150 and 1000 bytes. Gzipping files below 150bytes can actually make them larger.

 

1.Write your web page content to make compression most effective.

2.Don't use gzip for image or other binary files.

 

Remove unused CSS

  • Remove any inline style blocks containing CSS that is not used by the current page.
  • If your site uses external CSS files shared among multiple pages, consider splitting them into smaller files containing rules for specific pages.
  • If a page references style rules that are not needed right at startup, put them in a separate .css file and defer loading of the file until the onload event is fired.
  • If you use JavaScript to generate styles, be sure that those functions aren't called from pages that don't use those styles. This may require some refactoring of JS code.

 

Minify JavaScript

 

Minify CSS

 

Minify HTML

 

Defer loading of JavaScript

For any file containing more than 25 uncalled functions, move all of those functions to a separate, external JS file. This may require some refactoring of your code to work around dependencies between files. (For files containing fewer than 25 uncalled functions, it's not worth the effort of refactoring.)

 

<scripttype="text/javascript">

// Add a scriptelement as a child of the body

functiondownloadJSAtOnload() {

var element =document.createElement("script");

element.src ="deferredfunctions.js";

document.body.appendChild(element);

}

 

// Check for browser support ofevent handling capability

if(window.addEventListener)

window.addEventListener("load",downloadJSAtOnload, false);

else if(window.attachEvent)

window.attachEvent("onload",downloadJSAtOnload);

elsewindow.onload = downloadJSAtOnload;

</script>

 

Optimize images

1.Choosean appropriate image file format.

The type of an image can have a drastic impact on the file size. Use these guidelines:

  • PNGs are almost always superior to GIFs and are usually the best choice. IE 4.0b1+, Mac IE 5.0+, Opera 3.51+ and Netscape 4.04+ as well as all versions of Safari and Firefox fully support PNG, including transparency. IE versions 4 to 6 don't support alpha channel transparency (partial transparency) but they support 256-color-or-less PNGs with 1-bit transparency (the same that is supported for GIFs). IE 7 and 8 support alpha transparent PNGs except when an alpha opacity filter is applied to the element. You can generate or convert suitable PNGs with GIMP by using "Indexed" rather than "RGB" mode. If you must maintain compatibility with 3.x-level browsers, serve an alternate GIF to those browsers.
  • Use GIFs for very small or simple graphics (e.g. less than 10x10 pixels, or a color palette of less than 3 colors) and for images which contain animation. If you think an image might compress better as a GIF, try it as a PNG and a GIF and pick the smaller.
  • Use JPGs for all photographic-style images.
  • Do not use BMPs or TIFFs.

2.Use an image compressor.

 

Serve scaled images

 

Serve resources from a consistent URL

1.Serve shared resources from a consistent URL across all pages in a site. 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值