Five methods to enable gzip compression for website Acceleration

Source: Internet
Author: User
Tags cpanel

Gzip can be used to compress multiple types of files. It has a high compression ratio for CSS, JS, and HTML files. Especially for websites that use many JS special effects, the compression ratio reaches 70% after Gzip is enabled. Therefore, enabling gzip compression can significantly accelerate the website, but it consumes a little server resources. In general, the advantage is greater than the disadvantage.

The following provides five methods to enable gzip compression:

Method 1. WordPress gzippy plug-in

This plug-in automatically enables gzip compression for Wordpress. After installation, it can be enabled.

Method 2. cpanel Panel website Optimization Options

If you use the cpanel panel, the "optimize Website" icon appears in the "software" area. Click "optimize Website" and select "compress all content ), then update settings to enable the website acceleration function.

Method 3. Enable gzip through index. php

Add the following code at the beginning of the index. php file in the WordPress root directory:

Ob_start ("ob_gzhandler ");

Note that you must place the statement in the define ('wp _ use_themes ', true) of the index. php file. Do not place the statement in the comment. For example, the content of the modified index. php file

Method 4. Set the php. ini file

Create a file named PHP. ini with the following content and upload it to the root directory of the website. It is applicable to spaces that support the zlib class library. You can check whether the space supports the zlib class library from the probe. Most of the space is supported.

Output_buffering = off
Output_handler =
Zlib. output_compression = on

NOTE: If WordPress enables static plug-ins (WP-Cache and cos-HTML-Cache), all static pages cannot be gzip, because zlib is only valid for dynamic pages.

Method 5. Set the. htaccess File

If the server supports the. htaccess file, add the following code to the. htaccess file in the WordPress root directory. If there is no. htaccess file, add the code and upload it to the WordPress root directory.

Php_value output_handler ob_gzhandler

You can also specify the file type to be compressed to save server resources by adding the following code to the. htaccess file. You can also set image/GIF
Image/JPEG
Add image/PNG. (Because GIF and jpg images are already compressed, do not expect how much water gzip can squeeze for you.
Yes ~)

<Ifmodule mod_deflate.c>
Addoutputfilterbytype deflate text/HTML text/CSS text/plain text/XML application/X-httpd-PHP application/X-Javascript
</Ifmodule>

According to the experiment, Gzip compression can be successfully enabled in methods 2, 3, and 4. Because 1st plug-ins need to be installed, and 5th need to be modified. htaccess (unfamiliar), no tests were conducted.

My compression results show that the compression ratio is as high as 26.4%, which is quite remarkable:

Webmaster tools web gzip compression Detection: http://tool.chinaz.com/Gzips/

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.