PHP Classes

PHP Minify JS, CSS, PHP and HTML: Reduce the size of source files in PHP, CSS or JS

Recommend this page to a friend!
  Info   View files Example   View files View files (16)   DownloadInstall with Composer Download .zip   Reputation   Support forum (2)   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 66%Total: 836 All time: 4,139 This week: 108Up
Version License PHP version Categories
minifier 1.0.4GNU General Publi...5.6PHP 5, Text processing, Compression, P...
Description 

Author

This package can reduce the size of source files in PHP, CSS or JS.

It provides a base class for parsing source code from files or strings. Subclasses are provided to reduce the size of code files of different languages.

Currently it can reduce the size of JavaScript, CSS, PHP and HTML. For PHP it uses the built-in php_strip_whitespace function by writing the code to a temporary file first.

The class is also able to minimize the size of inline Javascript and CSS styles within HTML pages, and creates CSS classes to replace repeated occurrences of tag style attributes.

Picture of Christian Vigh
  Performance   Level  
Name: Christian Vigh <contact>
Classes: 32 packages by
Country: France France
Age: 57
All time rank: 13810 in France France
Week rank: 10 Up1 in France France Up
Innovation award
Innovation award
Nominee: 20x

Winner: 3x

Example

<?php
   
// This example minifies file "example.css" and displays its minified contents
    // The original contents of the file are displayed only when working in non-cli mode
   
require ( "../../JavascriptMinifier.phpclass" ) ;

   
$input = "example.js" ;

   
$webmode = ( php_sapi_name ( ) != 'cli' ) ;

    if (
$webmode )
       {
        echo
"<h1>Contents of original file :</h1><pre>" ;
       
$contents = htmlspecialchars ( file_get_contents ( $input ) ) ;
        echo
"$contents</pre><br/><br/>" ;
        echo
"<h1>Contents of minified file :</h1><pre>" ;
        }

   
$minifier = new JavascriptMinifier ( ) ;
   
$minified_contents = $minifier -> MinifyFrom ( $input ) ;
    echo
$minified_contents ;

    if (
$webmode )
        echo
"</pre><br/><br/><h1>Size comparison :</h1><pre>" ;
    else
        echo
"\n\nSize comparison :\n" ;

    echo
"\tSource file : " . filesize ( $input ) . " bytes\n" ;
    echo
"\tMinified file : " . strlen ( $minified_contents ) . " bytes\n" ;


  Files folder image Files  
File Role Description
Files folder imageexamples (4 directories)
Plain text file CssMinifier.phpclass Class Class source
Plain text file HtmlMinifier.phpclass Class Minifies HTML
Plain text file JavascriptMinifier.phpclass Class Class source
Accessible without login Plain text file LICENSE Lic. License text
Plain text file Minifier.phpclass Class Class source
Accessible without login Plain text file NOTICE Data Auxiliary data
Plain text file PhpMinifier.phpclass Class Class source
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  examples  
File Role Description
Files folder imagecss (2 files)
Files folder imagehtml (2 files)
Files folder imagejs (2 files)
Files folder imagephp (2 files)

  Files folder image Files  /  examples  /  css  
File Role Description
  Accessible without login Plain text file example.css Data Auxiliary data
  Accessible without login Plain text file example.php Example Example script

  Files folder image Files  /  examples  /  html  
File Role Description
  Accessible without login HTML file example.html Doc. Documentation
  Accessible without login Plain text file example.php Example Example script

  Files folder image Files  /  examples  /  js  
File Role Description
  Accessible without login Plain text file example.js Data Auxiliary data
  Accessible without login Plain text file example.php Example Example script

  Files folder image Files  /  examples  /  php  
File Role Description
  Accessible without login Plain text file example.php Example Example script
  Plain text file example.phpclass Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:836
This week:0
All time:4,139
This week:108Up
User Ratings User Comments (1)
 All time
Utility:82%StarStarStarStarStar
Consistency:89%StarStarStarStarStar
Documentation:85%StarStarStarStarStar
Examples:78%StarStarStarStar
Tests:-
Videos:-
Overall:66%StarStarStarStar
Rank:717