alert-icon Empty input field
alert-icon Empty input field
Minify - JavaScript and CSS minifier
JSON Minifier QR Code Scanner HTML Minifier HTML Validator CSS Validator JS Validator
minify
Sample [+]

or, drop the file here

Select Language:
clear Clear copy Copy download Download
Star Star Star Star Star

How would you rate your experience?

Cancel Submit
description

Minify JS / CSS - JavaScript and CSS minifier

Minify JS and CSS using this online javascript / css compressor. You can paste .js or .css file, or just plain javascript or CSS code.

Make your website smaller and faster to load by minifying the JS and CSS code.

This JS and CSS minifier removes whitespace, strips comments, combines files, and optimizes/shortens a few common programming patterns. Minify JS / CSS comes with a huge test suite.

Use it in your projects

Simply add a dependency on matthiasmullie/minify to your composer.json file if you use Composer to manage the dependencies of your project:
composer require matthiasmullie/minify
Although it’s recommended to use Composer, you can actually include these files anyway you want.

Contribute

Dig into to the code. It’s MIT-licensed, so you’re allowed to do pretty much anything with it.
git clone [email protected]:matthiasmullie/minify.git
Fork the repository on GitHub, and send your pull requests! Any kind of help is welcome.

Bugs?

Please submit any issue you encounter. In order to easily grasp the issue, be as thorough as possible in describing the bug! Please include the original JavaScript or CSS code, the incorrect minified result and the expected result. Bonus points for including a pull request with the issue added to the test suite!

Documentation

Code coverage Code quality Latest version Downloads total License

Available methods, for both CSS and JS minifier, are:

__construct(/* overload paths */)

The object constructor accepts 0, 1 or multiple paths of files, or even complete CSS/JS content, that should be minified. All CSS/JS passed along, will be combined into 1 minified file.


use MatthiasMullie\Minify;
$minifier = new Minify\JS($path1,
$path2);

add($path, /* overload paths */)

This is roughly equivalent to the constructor.

$minifier->add($path3);
$minifier->add($js);

minify($path)

This will minify the files’ content, save the result to $path and return the resulting content. If the $path parameter is omitted, the result will not be written anywhere.

CAUTION: If you have CSS with relative paths (to imports, images, …), you should always specify a target path! Then those relative paths will be adjusted in accordance with the new path.

$minifier->minify('/target/path.js');

gzip($path, $level)

Minifies and optionally saves to a file, just like minify(), but it also gzencode()s the minified content.

$minifier->gzip('/target/path.js');

setMaxImportSize($size) (CSS only)

The CSS minifier will automatically embed referenced files (like images, fonts, …) into the minified CSS, so they don’t have to be fetched over multiple connections.

However, for really large files, it’s likely better to load them separately (as it would increase the CSS load time if they were included.)

This method allows the max size of files to import into the minified CSS to be set (in kB). The default size is 5.

$minifier->setMaxImportSize(10);

setImportExtensions($extensions) (CSS only)

The CSS minifier will automatically embed referenced files (like images, fonts, …) into minified CSS, so they don’t have to be fetched over multiple connections.

This methods allows the type of files to be specified, along with their data:mime type.

The default embedded file types are gif, png, jpg, jpeg, svg and woff.

$extensions = array(
 'gif' => 'data:image/gif',
 'png' => 'data:image/png',
 );
 $minifier->setImportExtensions($extensions);

Example Usage

Minify JavaScript

use MatthiasMullie\Minify;
 $sourcePath = '/path/to/source/css/file.js';
 $minifier = new Minify\JS($sourcePath);
 // we can even add another file, they'll then be
 // joined in 1 output file
 $sourcePath2 = '/path/to/second/source/css/file.js';
 $minifier->add($sourcePath2);
 // or we can just add plain js
 $js = 'var test = 1';
 $minifier->add($js);
 // save minified file to disk
 $minifiedPath = '/path/to/minified/js/file.js';
 $minifier->minify($minifiedPath);
 // or just output the content
 echo $minifier->minify();

Minify CSS

use MatthiasMullie\Minify;
 $sourcePath = '/path/to/source/css/file.css';
 $minifier = new Minify\CSS($sourcePath);
 // we can even add another file, they'll then be
 // joined in 1 output file
 $sourcePath2 = '/path/to/second/source/css/file.css';
 $minifier->add($sourcePath2);
 // or we can just add plain CSS
 $css = 'body { color: #000000; }';
 $minifier->add($css);
 // save minified file to disk
 $minifiedPath = '/path/to/minified/css/file.css';
 $minifier->minify($minifiedPath);
 // or just output the content
 echo $minifier->minify();
Other Tools
HTML Minifier JSON Minifier JSON Formatter HTML Formatter XML Formatter XML Validator JAVA Viewer YAML Validator HTML Decoder PHP Beautifier Excel to JSON SQL Formatter HTML to Markdown CSV Viewer Diff Checker JSON to JAVA JSON to PHP JSON to YAML XML to JSON YAML to JSON XML to YAML JSON to XML CSS Formatter JavaScript Beautifier YAML Formatter Markdown Formatter Text to HTML Converter CSV to JSON Converter CSS Validator HTML Validator Base64 Encoder Decoder SQL Minifier Text Minifier Lua Minifier XML Minifier HTML to PHP Converter HTML to TSV Converter JSON to CSV JSON to TSV JSON Viewer XML Viewer HTML Viewer JavaScript Validator Image to HTML Excel to HTML Excel to XML CSV to XML CSV to HTML XML to CSV XML to TSV XML to Excel JSON to Excel SQL to CSV Converter SQL to JSON Converter SQL to XML Converter SQL to YAML Converter XML to Java Converter CSV to SQL SQL to HTML Converter JSON to HTML OPML to JSON QR Code Scanner YAML to Excel XML to HTML HEX to HSV Converter HEX to RGB Converter HEX to CMYK Converter CMYK to HEX Converter CMYK to RGB Converter CMYK to HSV Converter HSV to HEX Converter HSV to RGB Converter RGB to HEX Converter RGB to HSV Converter RGB to CMYK Converter Html Code Generator Svg Viewer XML Compare Python Beautifier AI Code Generator Barcode Scanner QR Code Generator

AltStyle によって変換されたページ (->オリジナル) /