searchturbine / phpwee-php-minifier

Open-source (BSD) PHP inline minifier functions for HTML, XHTML, HTML5, CSS 1-3 and Javascript. http://searchturbine.com/php/phpwee
Other
79 stars 46 forks source link

phpwee-php-minifier

PHPWee is an inline PHP minifier for web resources. It lets you minify HTML4, HTML5, XHTML, CSS and JavaScript files in a single line of code.

The best bit is its free and open source under the BSD license.

Installing PHPWee

Installing PHPWee should only take a minute. Here are you 3 choices:

You can include all the necessary classes by simply including the phpwee-php-minifier/phpwee.php file.

require_once ("phpwee-php-minifier/phpwee.php");

Using PHPWee

How to compress HTML:

$minified_html = PHPWee\Minify::html($any_html);

This automatically compresses all inline scripts and stylesheets within the HTML document. Apply a 'data-no-min' attribute to a script or style to exclude it from minification.

How to compress CSS:

$minified_css = PHPWee\Minify::css($any_css);

How to compress JS:

$minified_js = PHPWee\Minify::js($any_js);

Spelling out out:


require_once ("phpwee-php-minifier/phpwee.php");

$html = file_get_contents("http://en.wikipedia.org/wiki/Minification_%28programming%29");
$minified_html = PHPWee\Minify::html($html);
// a 9.38% performance boost - in 3 lines of code!!

There are working examples in the /examples folder of the package.

PHPWee Performance

Even highly optimized sites such as wikipedia.com, github.com and W3Schools.com can reduce the size of their HTML payload using PHPWee html compression.

Performance Graph

Who Makes PHPWee ?

The PHPWee HTML compression technology is totally new. It actually parses HTML documents and removes unneeded spaces and verbosity without changing meaning in any way. The output is generally at least as W3C compliant as the input.

The Css compressor is built upon the CssMin package by Joe Scylla joe.scylla@gmail.com. The JavaScript compressor is built upon Douglas Crockford's JSMin.

PHPWee Purpose

PHPWee is built and maintained by http://searchturbine.com as part of their 20% codeshare policy. They can be contacted at community@seacrhturbine.com

PHPWee was designed as a pre-CDN optimizer for the searchturbine.com website - which is hosted on Github pages. It currently offers about 22% compression site-wide - and is used in the deployment process.

This technology would is ideally placed to be used in deployment scripts for websites, and would also fair wall as part of a CDN architecture.

PHPWee Improvements

We "eat our own dog-food". We will be using this package to optimize http://searchturbine.com - and will publish all results, insights and improvements.