Turn on Gzip compression to speed up your WordPress website loading and browsing speed

888u

Last update at :2024-02-09,Edit by888u

The loading speed of web pages is something that we webmasters must pay attention to. This tests the patience of viewers. The most terrible thing is that no search engine will be so patient and wait for a website that opens very slowly. This will directly affect the number of indexes on your website, which is serious. Affects the quality of your website. Today we are going to get to know Gzip. If the virtual host you purchase has limited traffic every month, if the blog has a large number of visits, or is charged based on traffic, then this is a lot of expenses, so we must Turn on the gzip function of the web page to compress the data output of the web page. Turning on the gzip compression function can reduce the amount of data requested each time a web page is opened. It not only saves host traffic, but also speeds up the loading speed of web pages. This is a win-win situation, so why not do it. Here are 5 commonly used methods to enable Gzip compression. Choose the method you like to use on your WordPress website.

Introduction to gzip

Gzip is used for file compression in UNIX systems. Files with the suffix .gz are often used in Linux, and they are in Gzip format. Nowadays, it has become a very common data compression format, or file format, used on the Internet. Gzip encoding over HTTP protocol is a technology used to improve the performance of WEB applications. High-traffic WEB sites often compress the data output to the user's browser after Gzip is turned on, which will reduce the amount of data transmitted through the network and increase browsing speed.

Turn on gzip

Method 1. Enable Gzip compression by modifying the index.php file

1. Download the index.php file in the root directory of the WordPress website to your local computer. Use professional web page or code editing software to open and edit it. Do not use the notepad that comes with the system. Pay attention to punctuation marks when filling in, and English input is required.

2. Find in the opened index.php:

define('WP_USE_THEMES', true);

Add after:

ob_start('ob_gzhandler')

This method is the simplest and recommended. However, there is a drawback, which is that after the WordPress system is upgraded, it needs to be reset. Method 2: Enable Gzip compression through .htaccess 1. If your website space or server supports .htaccess files, first, check if there is an .htaccess file in your root directory. If not, please create a file in txt format locally, and then upload it to your root directory. Rename to .htaccess. Please note that the location of the .htaccess file must be in the root directory. Then add the following code to .htaccess in the wordpress root directory, and then upload it to the wordpress root directory. 2. Use FTP software to log in to the WordPress blog website directory. 3. Right-click the .htaccess file - Edit and open the .htaccess file. Add any one of the three codes at the end. The first type:

php_value output_handler ob_gzhandler

Second type:

ExpiresActive On ExpiresByType image/gif A2592000 ExpiresByType image/jpeg A2592000 ExpiresByType image/png A2592000 ExpiresByType image/x-icon A2592000 ExpiresByType application/x-javascript A604800 ExpiresByType text/css A604800 SetOutputFilter DEFLATE AddOutputFilterByType DEFLATE text/html text/css image/gif image/jpeg image/png application/x-javascript

The third type

php_flag zlib.output_compression On php_value zlib.output_compression_level 8

Save the upload and overwrite the original file. Now your website has gzip enabled. Method 3: Enable Gzip compression through php.ini 1. If the server supports php.ini redefinition, you can add the following code to php.ini to enable gzip.

zlib.output_compression_level = number

2. Number is a value from 1 to 9, 1 has the lowest compression ratio, and 5 is recommended. Method 4: Install the gzippy plug-in to enable Gzip compression Download the wordpress plug-in Gzippy, click the install plug-in in the wordpress background - upload - select the file - install now. After the installation is completed, start the plug-in.

WordPress official website download Method 5: Use the built-in function of WP Super Cache caching plug-in to enable Gzip compression If your wordpress has installed the WP Super Cache caching plug-in, you can check the Compress pages so they’re served more quickly to visitors. (Recommended) item in the WP Super Cache settings-advanced options, so that you can also turn on Gzip compression. Method 6: Gzip compression of the entire WordPress site can also be achieved through the functions.php file. Copying the following code into the functions.php file of the current theme can also achieve full-site gzip compression for WordPress:

add_action('init', ' wpjam_gzip_compression'); function wpjam_gzip_compression(){ if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) { ob_start('ob_gzhandler'); }else{ ob_start(); } }

Notes and instructions

1. If the gzip function is disabled in the .htaccess file, you must also enable gzip in the .htaccess file after enabling it in the php.ini file, otherwise it will have no effect. 2. After turning on the gzip function of wordpress, the server will compress the page before transmitting it, which can effectively reduce the bandwidth usage of the server and speed up the page download. 3. Please also note that you can only choose one way to enable wordpress gzip compression, otherwise conflicts may occur, please keep this in mind. After testing, server compression is faster than PHP compression and is smaller after compression. So the best way is to let Apache perform gzip compression directly. If you cannot modify Apache's httpd.conf file, try modifying the php.ini file, and finally use the method of modifying the php file and WordPress hook.

Recommended site search: Hong Kong server, Korean proxy IP, Mainland China registration-free host, station group server, free cloud server, 6 yuan per year cloud server, foreign server, space server, high-defense US server, cm domain name,

Turn on Gzip compression to speed up your WordPress website loading and browsing speed

All copyrights belong to 888u unless special state
取消
微信二维码
微信二维码
支付宝二维码