PHP Classes

PHP Minify CSS and JavaScript: Compact and group CSS and JavaScript files

Recommend this page to a friend!
  Info   Demos   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2022-10-21 (5 months ago) RSS 2.0 feedNot enough user ratingsTotal: 242 This week: 1All time: 7,981 This week: 154Up
Version License PHP version Categories
minifyr 1.0.3MIT/X Consortium ...5PHP 5, Web services, Compression, Par...


This class can compact and group CSS and JavaScript files.

It can take CSS and JavaScript files and compact them removing whitespace and needless characters.

Multiple CSS or multiple JavaScript files can also be grouped in one.

The class can also call a Web service that will use the Uglify.js library to compact the files.

Picture of Rogério Taques
Name: Rogério Taques <contact>
Classes: 4 packages by
Country: Japan Japan
Age: ???
All time rank: 239210 in Japan Japan
Week rank: 82 Up1 in Japan Japan Up



Latest Version

Minifies and group CSS or JS scripts.

If you're interested on save bandwith, reduce the load time and speed up your website or web application, then, Minifyr is good for you.

How to use

Fork (or download) this project;

Copy and paste the "minifyr.php" file into any folder from your project. This's the class.

For example:

/ (project root directory)
/ classes/minifyr.php
/ ...

Now create the script that is gonna use it for minify the resources you need.

As an example, create a file called _min.php_ in the root folder of your project, like below:

/ (project root directory)
/ classes/minifyr.php
/ min.php
/ ...

So, you can use the following code to make it happen:


// get settings and files to minify
// options are:
//   f			- Required. File or comma separated file list
//	 screen	- Optional. Void. Forces the download of minified file.
// 	 debug	- Optional. Void. When given, skip minification.
// @use http://domain.tld/min.php?f=assets/my.css[&screen[&debug]]

$debug  = isset( $_GET[ 'debug' ] ) ? TRUE : FALSE;
$screen = isset( $_GET[ 'screen' ] ) ? TRUE : FALSE;
$files  = isset( $_GET[ 'f' ] ) ? $_GET[ 'f' ] : NULL;

$m = new RT\Minifyr($debug, $screen);
$m->files( explode(',', $files) )
  ->compression(true)   // can be true/false. enables the gzip compression 
  ->cache(true)         // can be true/false. enables header for caching 
  ->uglify(true)        // can be true/false. uglify js codes
  ->expires('...')      // a string that defines the expiration date
  ->charset('...')      // the charset. default is utf-8
  ->files([])           // an array of strings containing files paths
  ->file('...')         // when only one file, a string with file path 
  ->render(false);      // renders the output. 
                        // if a true boolean is given, returns the output as string.

Now, everything you have to do is call it in your HTML file:

<link type="text/css" media="all" href="min.php?f=path/to/css/file.css" />

That's it. Easy and simple. A piece of cake! :)


These are the options you can pass:

| Option | Sample | Description | | --------- | ------ | ---------- | | f | min.php?f=file-path.css | It's the file to be minified. * | | screen | min.php?screen&f=... | It's the way to render the content on browser instead return it as a file. | | debug | min.php?debug&f=... | It's a way to don't minify the content. That helps you for debug your codes. |

Advanced usage for:

Option f : string

You can also pass a list of files. In this case, all files will be loaded and will be returned minified as a unique file. This technique is interesting to reduces the number of calls you make to your server. To pass a list of files, you should give file names separated by comma (,):



You can also load external resources. To do that, just pass the file with a prefix: external|.


min.php?f=external|[, ...]


1.6 Added support for external files. Prevent double minification on already minified files.

2.0 Refactored from a "script mode" to a "class mode". New features added.

  Not minifiedExternal page   MinifiedExternal page   Debug modeExternal page  

Open in a separate window

Open in a separate window

  Files folder image Files  
File Role Description
Files folder imagesample (2 files)
Accessible without login Plain text file LICENSE Lic. License text
Plain text file minifyr.php Class Class source
Accessible without login Plain text file Doc. Documentation

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

 Version Control Unique User Downloads Download Rankings  
This week:1
All time:7,981
This week:154Up