Fastest site? minimize WordPress files and PHP in general

WordPress or in general another PHP site? A few days ago we showed you the of speedtests of iGuRu.gr at GTMetix. The rating you saw is the result of hard work and many hours of coding.

Below we will describe the steps to minimize WordPress files and generally any PHP site.WordPress WordPress code

We will need the minify framework from Google Code.

Download Google's minify framework. After we will have to see where to place it. According to :

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 in iguru.gr/min/ in / that is where the WordPress software is, but in the min folder. The zip already includes a min folder.

So upload with ftp from the file minify-version>.zip που κατεβάσατε το φάκελλο min στο σημείο /. Στη δικό μας παράδειγμα, όπως προαναφέραμε είναι στο iguru.gr/min

The Minify PHP function iguru_minify_html is capable for minimization (minifying) HTML, inline JavaScript, and inline to CSS using minify PHP framework.

Below you should change the point where you have put it

function iguru_minify_html ($buffer) { if (is_user_logged_in()) { $buffer .= ""; return $buffer; // for logged in users minify is not required } else { $initial = strlen($buffer); $minify_lib_path = '/srv/www/iguru.gr/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/Minify/Loader.php"); Minify_Loader::register(); require_once("$minify_lib_path/lib/Minify/HTML.php"); ini_set('include_path', ini_get('include_path').":$minify_lib_path/lib"); require_once("$minify_lib_path/lib/Minify/CSS.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 .= ""; return $buffer; } }

And now we can move on, using the above minify mode in WordPress or any application PHP.

Place the above function inside  functions.php and you're ready.

You can try your GTMetix page to see the results.

Let's say that for better and better results you should find someone special. IGuRu.gr does not undertake service in case something goes wrong with the above code.

Use it at your own risk.

iGuRu.gr The Best Technology Site in Greecefgns

every publication, directly to your inbox

Join the 2.087 registrants.

Written by giorgos

George still wonders what he's doing here ...

Leave a reply

Your email address is not published. Required fields are mentioned with *

Your message will not be published if:
1. Contains insulting, defamatory, racist, offensive or inappropriate comments.
2. Causes harm to minors.
3. It interferes with the privacy and individual and social rights of other users.
4. Advertises products or services or websites.
5. Contains personal information (address, phone, etc.).