How to adjust JS file to improve Web speed?

Source: Internet
Author: User

Intermediary transaction SEO diagnosis Taobao guest Cloud host technology Hall

With the increasing demand of Internet users, coupled with the growing popularity and popularity of mobile devices, the speed of Web site loading is more and more concerned by stationmaster. Site loading time is a major reason for the loss of users, ordinary users will not have the patience to wait for a very long web page load, and this directly affects the operation of the site.

In the Baidu Webmaster Platform page optimization proposal, Baidu focused on checking the site load time this piece, and for the first byte time, using long links, enable gzip compression, picture compression, set static content caching time, reasonable use of cookies, combining CSS and JS files and other aspects of the proposed optimization. These are not all said, the following talk about how to set up JS Web page to improve load speed.

  

Most of the pages will be the JS file in the head, but many browsers will use a single thread to do page loading and JS script processing, that is, when the execution engine encountered script code, at this time the load behind the page must wait for JS execution finished. If JS executes slowly, then the user can only stoning, when the user is likely to turn off the Web page.

ie8,firefox3.5 and Chrome2 have realized the parallel download of JS, this is quite good, automatically shorten the execution time of JS, but will hinder the download of some other resources. For example, JS file after the picture code to wait until the completion of JS is completed before loading, which may cause the user waiting, how to do it?

JS file Position Adjustment

Since the JS file in front of the delay after the loading of the code, then we can consider to put JS in front of the/body or thicker, so that the script before the perfect rendering of HTML, will not allow users to see a blank page, improve the experience degree.

Second, merge JS file

Although the JS file location after the move can let other code first load, but in the execution of the JS file time is more time-consuming, if more than JS file, you need to do a lot of "get" request, prolong the loading speed. Then naturally we want to reduce the GET request. There are usually two scenarios:

First: Merge JS files, such as 1.js, 2.js and 3.js merged.

Second: Use third-party tools, such as Minify in PHP.

About the merge JS, is used more, most of the site is external call JS, and now the call of JS merged together is very common.

Third, the final implementation of JS file

Whether you put the JS file at the end of the foot, or merge JS file, are palliative, that is, unlimited to shorten JS execution time, and avoid JS execution and code loading conflicting, but this just let the HTML code file, even though loading, or not very good to avoid JS execution and code loading mutual resistance, When the Web page becomes more and more complex, JS files more and more, this block will become more and more big.

So the best way is to let JS file finally loaded, that is, the page is all rendered after the addition of JS script, when the Window.onload event triggered, we began to load JS, so completely will not allow users to wait for the site's subject content loading, there are many large Web sites is to use this. This need to work with the technical staff to complete or their own hands on the internet to find code, but personal advice or teach the people to complete, they can learn first, lest there is a mistake, outweigh the gains.

The above is a personal humble opinion, so unless you need to put the JS file in the head position, no side suggest that the JS file should be placed before or after the/body, and reasonable merge JS file, reduce get times, if unrestricted can also set JS final implementation, Of course, without affecting the overall UI of the Web page, this greatly improves the loading speed of the page theme information. Improve the user experience of the site.

Article from SEO Blog: Http://blog.sina.com.cn/mumuhouzi have any questions welcome to discuss!

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.