|
wikimedia/minify
Minification of JavaScript code and CSS stylesheets
|
JavaScript Minifier. More...
Static Public Member Functions | |
| static | minify ( $s, $onError=null) |
| Returns minified JavaScript code. | |
| static | createMinifier () |
| Create a minifier state object without source map capabilities. | |
| static | createSourceMapState () |
| Create a minifier state object with source map capabilities. | |
| static | createIdentityMinifier () |
| Create a MinifierState that doesn't actually minify. | |
| static | minifyInternal ( $s, $mapGenerator=null, $onError=null, $onDebug=null) |
| Minify with optional source map. | |
JavaScript Minifier.
This class is meant to safely minify JavaScript code, while leaving syntactically correct programs intact. Other libraries, such as JSMin require a certain coding style to work correctly. OTOH, libraries like jsminplus, that do parse the code correctly are rather slow, because they construct a complete parse tree before outputting the code minified. So this class is meant to allow arbitrary (but syntactically correct) input, while being fast enough to be used for on-the-fly minifying.
This class was written with ECMA-262 8th Edition in mind ("ECMAScript 2017"). Parsing features new to later editions of ECMAScript might not be supported. It's assumed that the input is syntactically correct; if it's not, this class may not detect that, and may produce incorrect output.
See also:
|
static |
Create a MinifierState that doesn't actually minify.
|
static |
Create a minifier state object without source map capabilities.
Example:
JavaScriptMinifier::createMinifier() ->addSourceFile( 'file.js', $source ) ->getMinifiedOutput();
|
static |
Create a minifier state object with source map capabilities.
Example:
$mapper = JavaScriptMinifier::createSourceMapState() ->addSourceFile( 'file1.js', $source1 ) ->addOutput( "\n\n" ) ->addSourceFile( 'file2.js', $source2 ); $out = $mapper->getMinifiedOutput(); $map = $mapper->getSourceMap()
|
static |
Returns minified JavaScript code.
| string | $s | JavaScript code to minify |
| callable | null | $onError | Called with a ParseError object |