How WordPress implements Gzip compression

Everyone knows,Compression affects the overall loading speed of the website andSEOA significant improvement,But many people use plugins orcdnwhich providedGZIPDecompression,This may make the overall optimization of the website not obvious,It is inevitable if there are some bugs in the plug-in.

About using codeGZIPcompression:

1、Put in the template directorystyle.cssMake a copy,namedstyle.css.php,Followed bystyle.css.phpAdd this sentence at the top:

<?php if(extension_loaded(‘zlib’)) {ob_start(‘ob_gzhandler’);}header("Content-type: text/css"); ?>

Add the following code at the end:

<?php if(extension_loaded(‘zlib’)) {ob_end_flush();} ?>

2、Modify as followsheader.phpmiddlecssconnection

The original:

<link rel="stylesheet" type="text/css" media="screen" href="/style.css"/>

after edited:

<link rel="stylesheet" type="text/css" media="screen"href="/style.css.php"/>

right now,yourCSSJust beGzipcompression了,同样的方法可以compressionyourJS.Just inJSAdd the following code at the top:

<?php if ( extension_loaded(‘zlib’) ) {ob_start(‘ob_gzhandler’);}header("Content-Type: text/javascript"); ?>

What to do if you don’t know how to use code and need to use plugin



Use documentation&download

There isSUPERPlug-in tutorial,也是做静态文件compression的



Jump item


Original tutorial reprinted and indicated the source,Give Xia Rou a motivation

The above is《How WordPress implements Gzip compression》,For more tutorials, please go to《WordPressTechnical Tutorial》.

Related Article
6 excellent WordPress SEO plugins

Article directory [hidden] What is WordPress SEO plugin?Why WordPress SEO plugin?Three reasons to use WordPress SEO pluginWhat to look for Read more

WordPress gets statistics on the number of images in an article

as far as I knowWordPressThere is no function to count the number of pictures in the article,So if you want Read more

WordPress batch change domain names in articles

This tutorial is packaged and replaced for my entire site,But it can also be used to change the domain name Read more

How to prevent articles with duplicate titles from being published?

Prevent publication of articles with the same title  I usually post articles for external links or something,The webmasters are busy,Sometimes Read more

Leave a Reply

Your email address will not be published. Required fields are marked *

To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-spam image