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 i.e.

Step 3

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

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/

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.


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!

  • Howard

    Great article, you were deatailed and layed out some great facts, just a couple questions though. How does the compression of the JS files compare to using the UglifyJS libraries? Is there any obfuscation with this method, such as variable shortening and similar? UglifyJS seems to be the go to library for all JS these days. Seems like it only makes use of YUI?

    I have had great luck using the online tools available, while its not the same as on the fly. I like to control how I release my production code. My favorite that makes use of UglifyJS for all my minify JS needs is . They are also going to release a CSS tool soon, at least that is what I have read.

  • Pingback: HTML, Inline JS & Inline CSS Minify PHP | Various stuff()

  • Hello Howard – Thanks for reading a article. YUI library does good job even though how to implementation dynamic and ongoing release with maintenance is another bottleneck.

    Minify library does on-the-fly compress and minify on first request. For subsequent request it deliver from already manipulated files. So no harm in performance.


  • kbhgames

    Hi, i really like this article, but when i follow your instruction for wordpress, I got a blank page.

    Can you help me?

  • kbhgames

    i used error_reporting(E_ALL|E_STRICT) to show the errors but there was no error?

    • Please following setting in php.ini to capture all errors and syntax errors into file. Then it is feasible to figure out problem area.

      display_errors = On
      error_reporting = E_ALL
      error_log = /var/log/php-errros.log (I believe you already have it)

      after this, share your error details.

      • kbhgames

        Thank you. I got the PHP Fatal error: Class ‘Minify_CommentPreserver’ error. I solved it by adding

        require (“$minify_lib_path/lib/Minify/Loader.php”);


        I have another question is it possible to minify html into one line?

        • For single line html, you have to strip newline character, I think php minify framework supports that. Please have a look on framework documentation.

          Note: Newline character strip might have impact on inline JS and CSS.

  • Mk

    Can I include “minify” in my commercial Project?

    • @mirelimbrea:disqus – Feel free to use it. All code snippet from myjeeva blog can be used, no issue at all :)


      • Mk

        Perfect :-) but can i also insert the library from ? I tried to read the license but I can’t understand if I can use it in a commercial project

        • @mirelimbrea:disqus – Thanks for bringing it up. myjeeva blog as well as my work at is available under MIT License. I have updated Footer and Term of use page with license info.

          I hope its helpful.