Summary of PHP website basic optimization methods. 1. use GZip to add the following code to the top of each PHP page :? Phpob_start (ob_gzhandler );? After this code is used, the server compresses all the code that needs to be sent to the client, and
1. use GZip
Add the following code to the top of each PHP page:
After this code is used, the server compresses all the code that needs to be sent to the client and decompress it in the browser to speed up website operation. This function can also save website space traffic.
2. do not abuse Javascript or Ajax
Use Javascript and Ajax only when necessary. do not abuse them. Some websites use too many unnecessary Ajax animations or use Ajax to load useless parts. In this way, Javascript files will become very large, but there are actually many other solutions to implement these functions.
3. images, header files, and HTTP requests
This is the most important part of this article. The more images, external files, and CSS style files referenced by a webpage, the slower the webpage is to load. Take some time to reduce image files and other external files so that they can be loaded more quickly. In addition, each time an image or external file is loaded, an HTTP request is generated, which will delay the loading time. You can use the following methods to compress webpage files, JS files, and CSS style files:
Webpage files: use GZip. See Article 1.
JS file: http://www.fmarcia.info/jsmin/test.html this site can effectively reduce the JS file size
CSS files: http://www.cssdrive.com/index.php/main/csscompressor/ this site can reduce the size of CSS files
4. limit the number of MySQL queries
Each request to the database slows down the webpage loading speed. It is difficult for network developers to control this point, but some details can be optimized. For example, do not use the following code when selecting a database record:
SELECT * FROM database
Instead, use:
SELECT id, name, date, author, etc, blah, blah FROM database
This will consume less query time and reduce server load.
5.. php extension
Some people think that saving the JS file as filename.js.php and saving the CSS file as stylesheet.css. php will reduce the loading time, but I didn't notice the difference. Of course, if your website is slow, you can try this method. Of course, you need to use include () in each php file to load these files.
6,Http://www.websiteoptimization.com/
Go to this website and check your website. it will give you some suggestions on how to optimize your website. This function is used every time I create a new page.
Add the following code to the top of each PHP page :? Php ob_start ("ob_gzhandler ");? After this code is used, the server compresses all the code that needs to be sent to the client, and...