Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions HISTORY.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ Version 2.1.5
* more efficient JS minification when using CC/YUIC
* Closure Compiler uses cURL when allow_url_fopen is off
* Missing file notices when using groups
* Changed README.txt to README.md, styling it to markdown
* Removed local file requires
* Added composer.json for packaging management with composer

Version 2.1.4
* Option to minify JS with Closure Compiler API w/ JSMin failover
Expand Down
125 changes: 125 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
MINIFY
====

*Minify is an HTTP content server. It compresses sources of content
(usually files), combines the result and serves it with appropriate
HTTP headers. These headers can allow clients to perform conditional
GETs (serving content only when clients do not have a valid cache)
and tell clients to cache the file for a period of time.*

More info: [http://code.google.com/p/minify/][1]


----------


Wordpress User
-------------

These WP plugins integrate Minify into WordPress's style and script hooks to
get you set up faster.

- [http://wordpress.org/extend/plugins/bwp-minify/][2]
- [http://wordpress.org/extend/plugins/w3-total-cache/][3]


----------


Installation
------------

**Using composer:**

NOTE: Check [Composer Starting Guide][4] for a more detailed explanation on how using composer to download and manage this package.

1. Download composer.phar from [here][5] or downloading through the console/command line by using this command in your project root folder: `curl -s https://getcomposer.org/installer | php`
2. Create a ***composer.json*** file in your project root directory
3. Although Minify is accessible in the packagist repository, this fork is not, so you have to put these lines in your ***composer.json*** file:


{
"repositories": [
{
"name": "minify/minify",
"type": "git",
"url": "https://github.com/tivie/minify.git"
}
],
"require": {
"minify/minify": "2.1.5"
}
}

4. Then run (again in your project root directory) `php composer.phar install`


**Zipped Download:**

You can also download **Minify** zipped directly from github, but this package is prepared for Composer Autoload.


----------


Configuration & Usage
---------------------

See the MIN.txt file and [http://code.google.com/p/minify/wiki/UserGuide][6]

Minify also comes with a URI Builder application that can help you write URLs
for use with Minify or configure groups of files. See here for details:

[http://code.google.com/p/minify/wiki/BuilderApp][7]

The cookbook also provides some more advanced options for magnification:

[http://code.google.com/p/minify/wiki/CookBook][8]


----------


Upgrading
---------

See UPGRADING.txt for instructions.



Unit Testing
------------

1. Place the /min_unit_tests/ directory as a child of your DOCUMENT_ROOT
directory: i.e. you will have: */home/example/www/min\_unit\_tests*

2. To run unit tests, access: *http://example.org/min\_unit\_tests/test_all.php*

(If you wish, the other test_*.php files can be run to test individual
components with more verbose output.)

3. Remove */min\_unit\_tests/* from your DOCUMENT_ROOT when you are done.


----------


File Encodings
--------------

Minify *should* work fine with files encoded in UTF-8 or other 8-bit
encodings like ISO 8859/Windows-1252. By default Minify appends
";charset=utf-8" to the Content-Type headers it sends.

Leading UTF-8 BOMs are stripped from all sources to prevent
duplication in output files, and files are converted to Unix newlines.


[1]: http://code.google.com/p/minify/
[2]: http://wordpress.org/extend/plugins/bwp-minify/
[3]: http://wordpress.org/extend/plugins/w3-total-cache/
[4]: http://getcomposer.org/doc/00-intro.md
[5]: http://getcomposer.org/download/
[6]: http://code.google.com/p/minify/wiki/UserGuide
[7]: http://code.google.com/p/minify/wiki/BuilderApp
[8]: http://code.google.com/p/minify/wiki/CookBook
68 changes: 0 additions & 68 deletions README.txt

This file was deleted.

40 changes: 28 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
{
"name": "oyatel/minify",
"description": "Minify is a PHP5 app that helps you follow several rules for client-side performance. It combines multiple CSS or Javascript files, removes unnecessary whitespace and comments, and serves them with gzip encoding and optimal client-side cache headers",
"authors": [
{
"name": "Even Andre Fiskvik",
"email": "eaf@oyatel.com"
}
],
"require": {},
"autoload": {
"classmap": ["min/lib/"]
"name": "minify/minify",
"description": "Minify is a PHP5 app that helps you follow several rules for client-side performance. It combines multiple CSS or Javascript files, removes unnecessary whitespace and comments, and serves them with gzip encoding and optimal client-side cache headers",
"keywords": ["js","javascript"],
"homepage": "http://code.google.com/p/minify/",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Ryan Groove",
"email": "ryan@wonko.com",
"homepage": "http://code.google.com/p/minify/",
"role": "Original Author"
},
{
"name": "Steve Clay",
"email": "steve@mrclay.org",
"homepage": "http://code.google.com/p/minify/",
"role": "Original Author"
},
{
"name": "Even Andre Fiskvik",
"email": "eaf@oyatel.com",
"role": "Mantainer, Composer Adaptation"
}
}
],
"autoload": {
"classmap": ["min/lib/"]
}
}
6 changes: 4 additions & 2 deletions min/lib/Minify.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,11 @@ public static function setCache($cache = '', $fileLocking = true)
*
* @param array $options controller/serve options
*
* @return mixed null, or, if the 'quiet' option is set to true, an array
* @return null|array if the 'quiet' option is set to true, an array
* with keys "success" (bool), "statusCode" (int), "content" (string), and
* "headers" (array).
*
* @throws Exception
*/
public static function serve($controller, $options = array())
{
Expand Down Expand Up @@ -290,7 +292,7 @@ public static function serve($controller, $options = array())
throw $e;
}
self::$_cache->store($cacheId, $content);
if (function_exists('gzencode')) {
if (function_exists('gzencode') && self::$_options['encodeMethod']) {
self::$_cache->store($cacheId . '.gz', gzencode($content, self::$_options['encodeLevel']));
}
}
Expand Down
121 changes: 121 additions & 0 deletions min/lib/Minify/ClosureCompiler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?php
/**
* Class Minify_ClosureCompiler
* @package Minify
*/

/**
* Compress Javascript using the Closure Compiler
*
* You must set $jarFile and $tempDir before calling the minify functions.
* Also, depending on your shell's environment, you may need to specify
* the full path to java in $javaExecutable or use putenv() to setup the
* Java environment.
*
* <code>
* Minify_ClosureCompiler::$jarFile = '/path/to/closure-compiler-20120123.jar';
* Minify_ClosureCompiler::$tempDir = '/tmp';
* $code = Minify_ClosureCompiler::minify(
* $code,
* array('compilation_level' => 'SIMPLE_OPTIMIZATIONS')
* );
*
* --compilation_level WHITESPACE_ONLY, SIMPLE_OPTIMIZATIONS, ADVANCED_OPTIMIZATIONS
*
* </code>
*
* @todo unit tests, $options docs
* @todo more options support (or should just passthru them all?)
*
* @package Minify
* @author Stephen Clay <steve@mrclay.org>
* @author Elan Ruusamäe <glen@delfi.ee>
*/
class Minify_ClosureCompiler {

/**
* Filepath of the Closure Compiler jar file. This must be set before
* calling minifyJs().
*
* @var string
*/
public static $jarFile = null;

/**
* Writable temp directory. This must be set before calling minifyJs().
*
* @var string
*/
public static $tempDir = null;

/**
* Filepath of "java" executable (may be needed if not in shell's PATH)
*
* @var string
*/
public static $javaExecutable = 'java';

/**
* Minify a Javascript string
*
* @param string $js
*
* @param array $options (verbose is ignored)
*
* @see https://code.google.com/p/closure-compiler/source/browse/trunk/README
*
* @return string
*/
public static function minify($js, $options = array())
{
self::_prepare();
if (! ($tmpFile = tempnam(self::$tempDir, 'cc_'))) {
throw new Exception('Minify_ClosureCompiler : could not create temp file.');
}
file_put_contents($tmpFile, $js);
exec(self::_getCmd($options, $tmpFile), $output, $result_code);
unlink($tmpFile);
if ($result_code != 0) {
throw new Exception('Minify_ClosureCompiler : Closure Compiler execution failed.');
}
return implode("\n", $output);
}

private static function _getCmd($userOptions, $tmpFile)
{
$o = array_merge(
array(
'charset' => 'utf-8',
'compilation_level' => 'SIMPLE_OPTIMIZATIONS',
),
$userOptions
);
$cmd = self::$javaExecutable . ' -jar ' . escapeshellarg(self::$jarFile)
. (preg_match('/^[\\da-zA-Z0-9\\-]+$/', $o['charset'])
? " --charset {$o['charset']}"
: '');

foreach (array('compilation_level') as $opt) {
if ($o[$opt]) {
$cmd .= " --{$opt} ". escapeshellarg($o[$opt]);
}
}
return $cmd . ' ' . escapeshellarg($tmpFile);
}

private static function _prepare()
{
if (! is_file(self::$jarFile)) {
throw new Exception('Minify_ClosureCompiler : $jarFile('.self::$jarFile.') is not a valid file.');
}
if (! is_readable(self::$jarFile)) {
throw new Exception('Minify_ClosureCompiler : $jarFile('.self::$jarFile.') is not readable.');
}
if (! is_dir(self::$tempDir)) {
throw new Exception('Minify_ClosureCompiler : $tempDir('.self::$tempDir.') is not a valid direcotry.');
}
if (! is_writable(self::$tempDir)) {
throw new Exception('Minify_ClosureCompiler : $tempDir('.self::$tempDir.') is not writable.');
}
}
}
Loading