WordPress or any other PHP site in general? A few days ago we showed you the results of the iGuRu.gr speedtests on GTMetix. The score you saw is the result of hard work and many hours of coding.
Below we will describe the steps for minifying WordPress files and any PHP site in general.
We will need the minify framework from Google Code.
Download Google's minify framework. After downloading, we need to figure out where to place it. According to the company:
Performing HTML, Inline JavaScript and Inline CSS: we can place the minify PHP framework anywhere ie inside or outside docroot.
In our case we can put it at secnews.gr/min/ in / which is where the WordPress software is, but inside the min folder. The zip already includes a min folder.
So upload with ftp from the minify
The Minify PHP function iguru_minify_html is capable of minifyingHTML, inlining JavaScript, and inlining CSS using the minify PHP framework.
Below you will need to change the point where you have placed the script
function iguru_minify_html ($buffer) { if (is_user_logged_in()) { $buffer .= "<!-- User is loggedin, compression is not applied. --> "; return $buffer; // for loggedin users minify is not required } else { $initial = strlen($buffer); $minify_lib_path = '/srv/secnewsgr.kinsta.cloud/min'; // use your own path, where you put the minify framework if (!class_exists('Minify_HTML')) { // Line no. 10 & 11 is only applicable to minify v2.1.7 require("$minify_lib_path/lib/Loader.php"); require_once("$minify_lib/Minify.php"); ini_get('include_path'); require_once("$minify_lib/Minify.php"); require_once("$minify_lib_path/lib/JSMin.php"); } // Calling minify function with HTML content $buffer = Minify_HTML::minify($buffer, array('cssMinifier' => array('Minify_CSS', 'minify'), 'jsMinifier' => array('JSMin', 'minify'))); $final = strlen($buffer); $savings = round((($initial-$final)/$initial*100), 3); $buffer .= "<!-- Uncompressed size: $initial bytes; Compressed size: $final bytes; $savings% savings --> "; return $buffer; } }And now we can move on, using the above minify function in WordPress or any PHP.
Place the above function inside functions.php and you're ready.
You can test your page in GTMetix to see the results.
Please note that for more accurate and better results you should find a specialist. iGuRu.gr does not undertake service in case something goes wrong with the above code.
Use it at your own risk.
