HTML, Inline JS & Inline CSS Minify PHP

Minify PHP – HTML, inline JavaScript and inline CSSMinify‘ word always pops up while optimizing and performance tuning for Web Application(s) around the world.  Typically it’s meant for HTML, JavaScript, CSS, Inline JavaScript and Inline CSS.  I would like to describe about minify PHP framework and leverage framework capabilities for PHP based application(s) and simple usage in WordPress blog without plugin.

minify is a PHP5 app/framework – It combines multiple CSS or Javascript files, removes unnecessary whitespace and comments, and serves them with gzip encoding and optimal client-side cache headers.  Minify PHP framework implements rules from Yahoo Exceptional Performance

myjeeva blog minify (HTML, Inline JS & CSS) have been done using minify PHP framework and this article born from it.

Article scope is to do minify of HTML, Inline JS, and Inline CSS.  Most important part is, minify PHP framework doesn’t break your web page (Google Adsens or any ads, inline JavaScript and inline CSS).  It’s is best to leverage on 🙂


How to achieve Minify in WordPress or PHP

Step 1

Download minify framework from Google Code

Step 2

Choose an appropriate location for minify PHP framework.  Based on usage we can choose location, as per below-

  • Performing HTML, Inline JavaScript and Inline CSS: we can place the minify PHP framework anywhere i.e. inside or outside docroot
  • Performing on-demand JavaScript and CSS combining with Minification (out of scope for this article)

As per point #1 and scope of the article, location for minify PHP framework is outside the docroot for myjeeva.com i.e.

Step 3

Extract the downloaded archive minify-<version>.zip and upload the directory min into  /srv/www/myjeeva.com.

Step 4

Minify PHP function myjeeva_minify_html is capable of minifying HTML, inline JavaScript, inline CSS (much more) using minify PHP framework.

Note: Update variable $minify_lib_path (line #7 ) value with appropriate absolute path as per your website/file system.

Step 5

Let’s move on, using above minify function in WordPress OR Any PHP application(s)

Place the function from Step 4 and below code snippet into  functions.php

Create a PHP file called minify.php and place the function from Step 4 then below code snippet.  As per article location of the  minify.php file is  /srv/www/myjeeva.com/minify.php

Step 6

Open up php.ini or custom php.ini, based on type of hosting plan you have and place the following line into it. Don't forget to save 🙂

Note: Kindly ensure execute and read permission for minify.php and min framework directory by web server.


Conclusion

You have successfully achieved the minify of HTML, inline JavaScript and inline CSS for WordPress blog and any PHP application(s). Simple and elegant way using minify PHP framework and myjeeva blog.

Thoughts and clarifications are welcome!