Web speed: Use CSS sprites to reduce picture requests

Source: Internet
Author: User
Keywords Speed

Intermediary transaction http://www.aliyun.com/zixun/aggregation/6858.html ">seo diagnose Taobao guest cloud host technology Hall

In the era of "user experience" as the center of the network, do you close the page because it is too slow to open the page? I believe many people's answer is yes. In the high-speed network era, do not challenge the patience of Guangdong netizens, or will only lead to users away from your site.

There are many ways to speed up a Web page, one of which is to reduce HTTP requests. Each site will use the picture, when a site has 10 separate pictures, it means that when browsing the site will be sent to the server 10 times HTTP request to load the picture. Here are some ways to reduce the picture request.

CSS Sprites: Most of the front-end developers called "CSS Wizard", the popular understanding is: More than a small picture together into a large picture, reduce the number of HTTP requests to reach the page speed. The following Taobao as an example, for you to explain the next CSS sprites how to achieve. If we want to display on the webpage "Today Taobao activity" this picture.

  

Implementation code:

<div style= "WIDTH:107PX; height:134px; Background:url (sprites.gif) no-repeat-133px-153px "></div>

Width: To position the picture. Height: To locate the height of the picture. (CSS sprites must define the size of the container, otherwise an error will be displayed)

Background:url (sprites.gif) The path to the background picture. No-repeat: Background does not repeat. The position of the -133px:x coordinates, the position of the -153px:y coordinates.

Some people may not understand this -133px and -153px is how to come, this coordinates is the small picture in the big picture The x coordinates and the y left coordinates, the following figure, the red point coordinates is in the big picture the x-coordinate coordinates is 133px y coordinates to 153PX. (coordinates can also be expressed as a percentage, such as: 50% 50%) Some people will suggest, why the coordinates are positive, you write a negative? Because you define a background picture in background this way, the default x y coordinate is 0 0. The following figure today Taobao activity picture coordinates 133px 153PX, so to use -133px-153px to zero to correctly display the picture.

  

The advantages of CSS sprites: You can reduce the number of HTTP requests, such as 10 separate images will be issued 10 HTTP request, combined into a large picture, only send an HTTP request, thereby increasing the load speed of the Web page.

The disadvantage of CSS sprites: Everything is good and there are drawbacks. Some people may like, some do not like, because every time the picture changes to this picture to add content, the image of the coordinate positioning to be very accurate will be slightly cumbersome. The coordinate positioning is fixed to an absolute value and therefore loses some of the flexible properties of center.

CSS sprites has both advantages and disadvantages. If you want to use, you should look at the Web page to load speed mainly or to maintain easy to the main.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.