Compressing the page input is to remove all the unused characters, and then all the code together, so for the SEO is helpful, but for the code is very poor readability, we often see a lot of web sites to do so, if you want to manually spaces HTML in the word to delete the very troublesome, So there is the PHP output compressed HTML page instance.
Is it possible to compress the HTML code for the server output?
Here is a function to compress HTML:
The code is as follows |
Copy Code |
function wpjam_minify_html ($html) { $search = Array ( '/>[^s]+/s ',//Remove the space behind the label '/[^s]+ '/(S) +/s '//combine multiple spaces into one ); $replace = Array ( ' > ', ' < ', ' \1 ' ); $html = Preg_replace ($search, $replace, $html); return $html; } |
For WordPress Blog, the above function and the following code copied to the current theme of the functions.php file, you can implement the output page HTML code compression:
The code is as follows |
Copy Code |
if (!is_admin ()) { Add_action ("wp_loaded", ' wp_loaded_minify_html '); function wp_loaded_minify_html () { Ob_start (' wpjam_minify_html '); } }
|
Of course, the above is the site SEO optimization, we have a better way is to combine the above page compression output and then the server gzip compressed open, so that the page will be smaller oh, about Apacheapache server open gzip Compression instance
http://www.bkjia.com/PHPjc/632740.html www.bkjia.com true http://www.bkjia.com/PHPjc/632740.html techarticle compressing the page input is to remove all the unused characters, and then put all the code together, which is helpful for SEO, but for the code readability is very poor, we often see ...