Home >Backend Development >PHP Tutorial >Summary of basic optimization methods for PHP websites_PHP tutorial

Summary of basic optimization methods for PHP websites_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-21 15:49:25768browse

1. Use GZip

Add the following code at the top of each PHP page:

php ob_start("ob_gzhandler");?>

After using this code, the server will compress all the code that needs to be sent to the client and decompress it in the browser, thus making the website run faster. This feature can also save website space traffic.

2. Don’t abuse Javascript and Ajax

Only use Javascript and Ajax when necessary, and never abuse them. Some websites use too many unnecessary Ajax animations, or use Ajax to load useless parts. In this way, the Javascript file will become very large, but in fact there are many other solutions to achieve these functions.

3. Pictures, header files and HTTP requests

This point is the most critical part of this article. The more images, external files, and CSS style files referenced by the webpage, the slower the webpage will load. Take the time to make image files and other external files smaller so they load faster. In addition, every time you load images and external files, an HTTP request is generated, which will definitely delay the loading time. You can use the following methods to compress web page files, JS files and CSS style files:

Web page file: Use GZip, please see the first article
JS file: http://www.fmarcia.info/jsmin/test.html This website can Effectively reduce the size of JS files
CSS files:http://www.cssdrive.com/index.php/main/csscompressor/ This website can reduce the size of CSS files

4. Limit the number of MySQL queries

Each request to the database will slow down the loading speed of the web page . Web developers make it difficult to control this, but optimizations can be made in a few details. For example, when selecting database records, do not use the following code:

SELECT * FROM database

Instead use:

SELECT id, name, date, author, etc, blah, blah FROM database

This will consume less query time and reduce the load on the server.

5. .phpextension

Some people think that saving the JS file as filename.js.php and the CSS file as stylesheet.css.php will reduce the loading time, but I didn’t notice this. difference. Of course, if your website's speed becomes very 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 to test your own website. It will give you some suggestions on how to optimize your website. I use this feature every time I create a new webpage.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/319520.htmlTechArticle1. Use GZip and add the following code at the top of each PHP page: ? php ob_start("ob_gzhandler");? After using this code, the server will compress all the codes that need to be sent to the client and display them in the browser...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn