How to easily compress WordPress website Gzip

Source: Internet
Author: User
When I used the Baidu webmaster tool to detect website optimization suggestions the other day, I found that Gzip compression was not enabled for my website, but I remember that it was previously enabled, why is Gzip compression disabled by Baidu?

When I used the Baidu webmaster tool to detect website optimization suggestions the other day, I found that Gzip compression was not enabled for my website, but I remember that it was previously enabled, why does Baidu find that Gzip compression is not enabled? After careful check, it turns out that the template was replaced. WordPress Gzip compression is divided into PHP program compression and template file compression, if you have enabled Gzip compression on the previous template, but you have not enabled the Gzip compression function after you change the template, you must enable it yourself.

How does a WordPress website perform Gzip compression? If you are looking for answers to these questions, I believe you may not be able to endure the website access speed, or you want to increase the website access speed and retain more search visitors. Now let's take a look at how to perform Gzip compression on WordPress websites. This site is compressed by Gzip.

What is Gzip compression?

Gzip is short for GNUzip. it is a file compression program of GNU Free software. It was developed by Jean-loupGailly and MarkAdler. The first public version was released in 0.1 and 1.0 in. GZIP was first created by Jean-loup Gailly and MarkAdler for file compression in the un ix system. We often use files suffixed with .gz in linux, which are in GZIP format. Nowadays, it has become a widely used data compression format on the Internet, or a file format.

Effect of Gzip compression

GZIP encoding on HTTP is a technology used to improve the performance of WEB applications. Large-traffic WEB sites often use GZIP compression technology to make users feel faster. This generally refers to a function installed on the WWW Server. When someone visits the website on this server, this function in the server compresses the webpage content and then transmits it to the visiting computer browser for display. Generally, the plain text content can be compressed to 40% of the original size. In this way, the transmission is faster, and the result is that you click the URL and it will be displayed soon. Of course, this will also increase the server load. This function module is usually installed on servers. GZIP compression is beneficial to the user experience. This function is usually enabled.

How to enable Gzip in WordPress

First, install the plug-in

In WordPress, most cache plug-ins have built-in Gzip compression enabled, whether it's the old Cache plug-in WP Super Cache, lightweight 1 Blog Cacher, or hyper Cache, you can start the Gzip web page compression function. If you have not installed these plug-ins, or these plug-ins have started the Gzip function but are not compressed, you may need to start the plug-in GZippy, but when you start the plug-in, remember to disable the Gzip of the cache plug-in itself, otherwise it may cause a conflict.

Installation steps: go to the background → ins → install ins → Search for ins (GZippy) → download and install → Enable. Can be done, you can go to the webmaster tool Gzip compression detection tool web site detection: http://tool.chinaz.com/gzips/

The disadvantage of using the plug-in is that it is prone to conflicts and incompatibility after the program is upgraded.

Second, modify the template

Modify the function template of the WordPress template to enable it. Don't worry, this method is also very simple, you don't even need to understand the code, just do it. Step: (through ftp or server background) Open → wordpress root directory/wp-content/themes/your topic/functions. php: use DW or notepad to open functions. php, the last "?>" Add the following code before the tag (the core code of the GZippy plug-in ):

Function gzippy (){

Ob_start ('OB _ gzhandler ');

}

If (! Stristr ($ _ SERVER ['request _ URI '], 'tinymce ')&&! Ini_get ('zlib. output_compression ')){

Add_action ('init ', 'gzippy ');

}

Save the file and upload it to overwrite the original file. The disadvantage of this method is that the blogger mentioned above, each time the template is changed, it needs to be reset.

Third, modify the program

Specifically, this method is to modify the WordPress source program to compress the Gzip file to be output. the specific step is to use the FTP tool to open the WordPress source program and find the index under the root directory of the website. php, and then open the file before the end of the program, that is, define ('WP _ USE_THEMES ', true); after this line, add the following code: ob_start ('OB _ gzhandler'); save the file and overwrite the file to take effect.

This is very simple, but there is a bad thing, that is, after each upgrade of the WordPress source code, it will no longer work and need to be set again. Of course, there are other methods, such as modifying the. htaccess file under the root directory and modifying the PHP configuration file php. ini. The preceding three methods are sufficient and easy to use. these methods are complex, so we will not detail them here.

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.