经常有浏览大公司web端产品的习惯,习惯在chrome开发者工具中的audits下面的Specify image dimensions,发现这个后面跟着的数字总是挺大的。我刚上班的时候,对这一块也不是很懂,有时候偷懒,都喜欢对外部的图片管他3721就对它设置一个宽高,完全不处理图片,或者直接不设置宽高,让图片自适应。到后来,慢慢发现这个css的渲染机制,对图片这一块的处理相当影响性能。
看看下面外文文章的规则:
- Specify dimensions that match those of the images themselves.
- Don’t use width and height specifications to scale images on the fly. If an image file is actually 60 x 60 pixels, don’t set the dimensions to 30 x 30 in the HTML or CSS.If the image needs to be smaller, scale it in an image editor and set its dimensions to match (see Optimize images for details.)
- Be sure to specify dimensions on the image element or block-level parent
- Be sure to set the dimensions on the
element itself, or a block-level parent. If the parent is not block-level, the dimensions will be ignored. Do not set dimensions on an ancestor that is not an immediate parent.
以上规则说明:
更多关于图片优化的建议,请移步这里
原文:http://www.cnblogs.com/calvinjs/p/4936663.html