Loading Speed is improved: the website construction program is written in detail.

Source: Internet
Author: User


This winter, I was most impressed by two websites, one being the 12306 train ticket purchase website and the other being the mobile phone official website. The two websites share a common feature, that is, the slow speed at the peak of concurrent access is unbearable. In fact, at least 90% of these two websites will be suspended in the face of tens of thousands of concurrent accesses. Even when there are not many visitors at ordinary times, the speed of opening many websites is unbearable. There are many reasons that affect website loading speed, such as server configuration, data center bandwidth quality, and interconnection lines. However, I feel that, website programming and resource integration also greatly affect the website operation speed, but many people do not pay enough attention to the comparison.

I. Merge website resources

Why is the ticket booking website of the Ministry of Railways so inadequate during high concurrency? The website was thoroughly analyzed by haoku. The general conclusion is that the website sent too many requests to the server when submitting the order, and the instantaneous access traffic was huge, leading to access request congestion. In fact, this problem exists on many websites, especially the enterprise websites of small and medium-sized companies. Once you understand the problem, you can easily solve it. The solution is to reduce the number of requests sent frequently by servers, and the most effective way is to merge resources. In this way, the loading time of the same call file will be extended, but the number of upstream downloads is reduced, improving the code running efficiency.

Generally, websites need to be externally loaded to three types of resources: CSS style sheets, JS scripts, and image materials. All three can be properly merged to minimize the number of website requests. As long as the purpose of CSS is to control the website style, if you merge all CSS into a file, you must place it in the

Ii. compressing web page elements

If the website resources are large, merging can reduce the time, but the problem still cannot be solved fundamentally. Because merging website resources mainly reduces the number of requests sent from the client to the server, the website resource size remains unchanged. Therefore, necessary compression of web page elements is another shortcut to speed up Website access. The first way to compress web page elements is to rewrite the website code. You must know that using DIV + CSS to layout the website program can reduce a lot of code than Table layout. In the future, when HTML5 technology is popularized, the website code volume will be further compressed. Avoiding code redundancy is an excellent way to reduce the website size, especially to delete unnecessary fee codes.

Currently, many websites are loading slowly, which is directly related to the image materials used by websites. If there are no special requirements, but the resolution of the website image display can be controlled at 72dpi, even if the image display quality is slightly lower, it is better than half-day loading. Therefore, if possible, keep the website image size below kb, and use as few high-resolution and high-quality image materials as possible on the website. Enabling Gzip compression through the server is also a good way to reduce the size of the Web page. I will have a personal experience. For a webpage of about 50 kb, after Gzip compression is enabled, it can be controlled at around 10 KB. It is not surprising that the web page compression rate is above 60%, so that the website runs fast.

3. Adjust the code position

Does code location affect website loading speed? The answer is yes. Here is a simple example. Many websites now have statistical programs. Most of them are implemented by calling external js, which usually place the statistics program at the bottom of the website. The purpose is to avoid loading too slowly because of JS loading outside the site, affecting the user experience of the entire website. This is obvious. If you place some large script programs in the header of a webpage, it will inevitably slow down the loading speed of a website. There are two principles that need to be adhered to adjust the website code location. One is that the Code called from the outside of the website should be placed in the back for loading as much as possible, because the external code is not controllable; the other is, it is mentioned that large script programs are placed behind the programs, especially some JS programs. If the website effect is not affected, adjust them to other codes for loading and execution.

Another problem, though unrelated to the code location, is easily overlooked by many programmers, that is, the rendering of web pages. For example, there is a <style = "border: none"> and <style = "border: 0"> In the CSS Code. There is no difference in the visual representation of the page, however, there is a difference between interpreting rendering in the browser. <Style = "border: none"> indicates that no border exists and no border rendering is required. However, <style = "border: 0"> indicates that a border exists, the width of the border is only 0. In fact, when the browser interprets the code, it does not render the border once. Similarly, there is the control of the website image size. Many Programmers think that if the image size is exactly the same as the standard, they do not need to define the image height and width. This will make the code concise enough, in fact, this understanding is wrong. If it is not defined, it means that the browser needs to identify it and then render the display. This process takes time.

As a professional website construction and Network Marketing Organization, pilot technology (http://www.joyweb.net.cn) has always believed that the user experience and marketing effect of the website is closely related to the speed of the website, especially in the heart of the people's heart impetuous now. Therefore, with the increasing popularity of network marketing, most people pay more attention to websites and give users a feeling. The fact that China Telecom, China Unicom, and other broadband carriers are now putting the fast speed on the agenda. This means that the Internet speed of ordinary Internet users will get faster and faster, and the effect of the speed or slowness of websites on the online marketing effect will become more and more obvious. Sometimes, even if someone else's Website Opens in half a second, it may lose a marketing opportunity. Therefore, if possible, please try your best to speed up website loading, even if it is 100 milliseconds or even shorter.


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.