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
WP-SUPER-CACHE
download
Use documentation&download
There isSUPERPlug-in tutorial,也是做静态文件compression的
onCSSwithJScombinedWordPressPlug-in
download
Jump item
上面是对onCSSwithJSmergeWordPress的Plug-in.
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》.