How PHP can improve page loading speed

Source: Internet
Author: User
This article mainly introduces how to improve the page loading speed of PHP, has a certain reference value, now share to everyone, have the need for friends can refer to

1. Reduce page requests:

From the Web operating principle, the IIS request is stateless, the server side has been connected and shut down continuously, if you can reduce the server request, the total time will be reduced.

Before I downloaded the 163 mailbox landing page picture when found that they only used a picture to complete the entire page of all the pictures, then I was puzzled, this is not the same as the usual website. However, to reduce the number of browser requests, using HttpWatch you will find that the total time of the request is greatly reduced. The same idea, in the CSS style, JavaScript code should also be done as far as possible in a file to reduce Web requests.

2, page compression technology, give us js,html code to thin body.

Jquery is the most lightweight class library of JS, its original class library is 242KB, compressed it unexpectedly only 91.6KB. Common compression tools are Google Closure Compiler, YUI Compressor, Jspacker, gzip. I often use gzip because it has the highest compression rate. After compressing it with the JDK, it will remove some spaces and replace our long variable names with very short ones.

3, style, behavior, structure separation.

When the page is accessed for the first time, the user can download the CSS,JS code, although the first time the page loads slowly, but the subsequent page will be much faster. When users visit other pages of this site, the CSS style and JS code are also referenced by other pages. Browser found that it has been downloaded, the next time you can not download. This will do a download, the effect of subsequent speed.

4. Using Stored Procedures

Before running the stored procedure, the database has been analyzed by syntax and syntax, and the optimized execution scheme is given. This compiled process can greatly improve the performance of SQL statements. Because most of the work that executes the SQL statement is completed, the stored procedure can be executed at a very fast speed. This precompiled SQL statement can be executed directly and saves a large part of the query time.

5. Some details:

Put the CSS style on the head, if JS a lot of words, put the JS code in the tail. This allows you to load the DOM structure of the page as much as possible before you can level the user experience. If JS a lot of big words, the page is not loaded, how to user experience to say it.

6, appropriate use of Ajax

Ajax seems to be a bit of a myth now, as if the Web page as long as Ajax, then there is no efficiency problem. In fact, this is a misunderstanding. Poor use of Ajax will not make your Web pages more efficient, but can reduce the efficiency of your pages. Ajax is really a good thing, but please don't overdo it. You should also consider the above guidelines when using AJAX.

7, as far as possible to use the style tool for our generated page style code, do your own style written in the style file. Try to write as universally as possible.

8. Page Cache

Cache technology is used in large-scale portals, which are space-time-changing technologies.

The cache is primarily intended to improve the reading speed of the data. Because of the traffic bottleneck between the server and the application client, when reading the bulk data, using the cache to directly serve the client can reduce the client-to-server data interaction, which greatly improves the efficiency of the program of two page accesses.

9, configure the site's entity tags:

This etag is not for the user, but for the browser cache. The etag is a mechanism by which the server tells the browser to cache whether the content in the cache has changed. With the ETag, the browser will know that the contents of the cache are not up-to-date and need not be re-downloaded from the server.

10, the use of CDN technology.

When we download things on the internet, we often see what "Southern Server", "Northern Server" is the use of CDN technology to improve download speed and stability.

The full name of the CDN is the Content Delivery network, which is the contents distribution networks. The basic idea is to avoid the bottleneck and link of the Internet which may affect the speed and stability of data transmission, and make the content transmission faster and more stable. By placing the node servers in the network, a layer of intelligent virtual network based on the existing Internet, the CDN system can re-direct the user's request to the nearest service node according to the network traffic and the connection of each node, the load condition and the distance and response time of the user. The goal is to enable users to get the content they need, solve the congestion of Internet network, and improve the response speed of users to visit the website (from Baidu Encyclopedia).

11. Compress the document using gzip:

Gzip encoding is a way to improve the performance of Web pages, not only to reduce storage space, but also to reduce the time required for transmission. Using gzip compression for files in your Web site can significantly increase page load speed while reducing the bandwidth consumption of your website.

12. The style sheet file is placed outside the call:

Put the JavaScript and CSS style sheet files that you need to use on the page in a different folder so that the files are cached when you open other pages of the site, speeding up the loading of your pages.

13. Weight loss for JavaScript files:

This method differs from the gzip compression feature, and there are many ways to narrow down a JavaScript document, such as removing unnecessary spaces and other tags. Reducing the script file can significantly improve the speed of Web page access.

14. Image using height and Width properties

The height and Width properties of each image allow the browser to know the length and width of the image before loading it, and to set aside a specified long lenient image to display after loading. Without these two properties, the browser also needs to process the page layout style once the picture has been read successfully, which slows down the page loading speed. Therefore, it is best to use the upper and wider properties in the case of fixed image size.

15.CSS file Compression Slimming

P+css is now fluent in the layout of the page, p defines the elements, CSS control display effect. So often we will write CSS to another one or more external link CSS file, and the CSS file code also has a lot of lines. We can use some CSS compression tools to remove unnecessary content in the CSS file, such as repeating the definition of style, space, and so on to thin body. You can try using the Cleancss tool to compress your CSS files.

16. Integrate CSS, JS files to reduce the number of HTTP requests

Today's Web pages have multiple images, CSS external file links, JavaScript external script links. So when accessing a Web page, the browser needs to request these files to the server multiple times. There is a lot of time difference between the request and the load. In particular, some Web pages have multiple small pictures, icon buttons of the page, how many pictures, the browser will need to request how much these small files, many will request these small image files will significantly affect the load speed of the page. So we should try to put small pictures together on a large PNG image, and then display the icon through the coordinates. Requesting a large picture at a time is much faster than asking for a small picture multiple times. Similarly, it's a good idea to integrate CSS and JavaScript into one file as much as possible to help speed up page loading.

17. Add a slash (/) to the directory address

If visitors click to access such a directory address: http://www.3haojob.com, go to open the index.html document in this directory. When the server receives the request it takes some time to analyze whether this is a file or a directory. But if we add a slash (/) at the end, the server will know that you are accessing a directory address and then simply load the default document index.html or index.php. This way the server does not have to take the time to analyze this address, but also play a role in accelerating. Labor Dispatch

The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!

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.