Combines. minifies, and serves CSS or Javascript files

Overview

Welcome to Minify!

Minify is an HTTP server for JS and CSS assets. It compresses and combines files and serves it with appropriate headers, allowing conditional GET or long-Expires.

Before 7 requests
After 2 requests

The stats above are from a brief walkthrough which shows how easy it is to set up Minify on an existing site. It eliminated 5 HTTP requests and reduced JS/CSS bandwidth by 70%.

Relative URLs in CSS files are rewritten to compensate for being served from a different directory.

Static file serving

Version 3 allows serving files directly from the filesystem for much better performance. We encourage you to try this feature.

Support

Post to the Google Group.

Installation

See the install guide.

Configuration & Usage

(Using 2.x? Here are the 2.x docs.)

See the user guide.

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

See the cookbook for more advanced options for minification.

More docs are available.

Unit Testing

  1. Install dev deps via Composer: composer install
  2. composer test or phpunit

Warnings

  • Minify is designed for efficiency, but, for very high traffic sites, it will probably serve files slower than your HTTPd due to the CGI overhead of PHP. See the FAQ and CookBook for more info.
  • If you combine a lot of CSS, watch out for IE's 4096 selectors-per-file limit, affects IE 6 through 9.
  • 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.

Acknowledgments

Minify was inspired by jscsscomp by Maxim Martynyuk and by the article Supercharged JavaScript by Patrick Hunlock.

The JSMin library used for JavaScript minification was originally written by Douglas Crockford and was ported to PHP by Ryan Grove specifically for use in Minify.

Comments
  • lessphp support

    lessphp support

    a lessphp port to minify, i've taken somebody else's work and rebased it to current master

    overall expression: a group with single .less file: worked

    @mrclay: could you drop your guidelines how to improve and make this work as you would intend?

    tasks:

    • [x] lessphp support
    • [x] support import statements (multiple file caching/monitoring)
    • [x] Convert Minify_Source::lastModifiedTime to ->getModifiedTime() #114
    • [x] getCache interface #120
    opened by glensc 24
  • Minify returning 400 Bad Request

    Minify returning 400 Bad Request

    Originally reported on Google Code with ID 78

    Minify version: 2.1.1
    PHP version: 5.2.7
    
    What steps will reproduce the problem?
    1. Installing
    2. Creating configuration file (attached)
    3. calling via any method.
    
    Expected output:
    
    Minified output of js / css file(s).
    
    Actual output:
    
    400 Bad Request
    
    Did any unit tests FAIL? Unknown.
    
    Please provide any additional information below.
    
    Request Headers:
    
    Host: www.devbrewards.co.uk
    User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.5)
    Gecko/2008120122 Firefox/3.0.5 (.NET CLR
     3.5.30729)
    Accept: text/css,*/*;q=0.1
    Accept-Language: en-gb
    Accept-Encoding: gzip,deflate
    Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
    Keep-Alive: 300
    Connection: keep-alive
    Referer: http://www.devbrewards.co.uk/
    Cookie: CAKEPHP=gr62h029k2buteruujlcb6fnn0;
    SESS55e30b91742880ca57848b3a725fc4b3=vnashmcr3vasft9c08divi9me2
    
    Response Headers:
    
    Date: Wed, 21 Jan 2009 09:57:01 GMT
    Server: Apache/2.2.10 (Win32) PHP/5.2.7-dev
    X-Powered-By: PHP/5.2.7-dev
    Content-Length: 24
    Connection: close
    Content-Type: text/html; charset=UTF8
    
    Response: HTTP/1.0 400 Bad Request
    
    

    Reported by ibnormedia on 2009-01-21 10:01:30


    - _Attachment: [groupsConfig.php](https://storage.googleapis.com/google-code-attachments/minify/issue-78/comment-0/groupsConfig.php)_ - _Attachment: [config.php](https://storage.googleapis.com/google-code-attachments/minify/issue-78/comment-0/config.php)_ Type-Defect Priority-Medium Status-Invalid 
    opened by mrclay 22
  • Bug compilation with bootstrap 3

    Bug compilation with bootstrap 3

    Hello, For whatever reason there is a problem with minify, if bootstrap.css uses (bootstrap 3) from the Less compilation.

    No notification but stylesheet not loaded

    opened by gtraxx 19
  • "File ... is outside $allowDirs ..." on Windows / Apache

    My webpage is directly under the document root, not in a sub directory. Using Apache (2.4) under Windows. I got every time the message "File ... is outside $allowDirs ...". Document root is: $min_documentRoot = dirname(DIR) and it gives the right document root back. No Sym-Links, but I also tried this: $min_symlinks = array('//' => $min_documentRoot);

    I found a work around for this by changing the line (near line 142 in /lib/Minify/Source/Factory.php) from if (strpos($spec['filepath'], $allowDir) !== 0) { to if (strpos($spec['filepath'], rtrim($allowDir, '/')) !== 0) {

    The whole block of (changed) code is here:

        if ($this->options['checkAllowDirs']) {
            foreach ((array)$this->options['allowDirs'] as $allowDir) {
                if (strpos($spec['filepath'], rtrim($allowDir, '/')) !== 0) {
                    throw new Minify_Source_FactoryException("File '{$spec['filepath']}' is outside \$allowDirs."
                        . " If the path is resolved via an alias/symlink, look into the \$min_symlinks option.");
                }
            }
        }
    

    I have no defined "$allowDir"s, but the variable is set and ends with a '/' that causes this wrong behavior.

    opened by BillyGeat 17
  • mtime based cache id problems

    mtime based cache id problems

    currently if using groupsConfig, then cache id becames simply max(mtime) of all files.

    so, the cache id will remain the same, if i add more files to the group having identical timestamp.

    i guess there should be added * NUMBER_OF_FILES to avoid this problem

    so i had in my groupsConfig.php:

      'l' => array(
          '/path/to/lazyload.js'
      ),
    

    then url built with was:

      g=l&1338376276
    

    later i added one more file:

      'l' => array(
          '/path/to/uaft.js',
          '/path/to/lazyload.js'
      ),
    

    and the url remained the same:

      g=l&1338376276
    

    as the files have identical timestamp:

    $ ls -l --full uaft.js lazyload.js 
    -rw-r--r-- 1 root root 1.3K 2012-05-30 14:11:16.000000000 +0300 lazyload.js
    -rw-r--r-- 1 root root 1.7K 2012-05-30 14:11:16.000000000 +0300 uaft.js
    

    expanding that timestamp:

    $ LC_ALL=C php -r 'echo strftime("%c %z\n", 1338376276);'
    Wed May 30 14:11:16 2012 +0300
    
    opened by glensc 17
  • minify takes up to 5min to compress js scripts when mbstring.func_overload is activated

    minify takes up to 5min to compress js scripts when mbstring.func_overload is activated

    Originally reported on Google Code with ID 176

    Minify version:
    PHP version:    5.2.12 
    
    What steps will reproduce the problem?
    1.deactivating mbstring.func_overload
    2.
    3.
    
    Expected output:
    
    Actual output:
    hte full result but never less than 3min. responsetime
    
    Did any unit tests FAIL? (Please do not post the full list)
    sorry, will going to test it.
    Please provide any additional information below. If this has to do with URI
    rewriting, please include your DOCUMENT_ROOT, the
    
    

    Reported by [email protected] on 2010-05-06 10:42:55

    Type-Defect Priority-Medium Status-NeedInfo 
    opened by mrclay 16
  • JQuery, TinyMCE endless 301 redirects

    JQuery, TinyMCE endless 301 redirects

    Originally reported on Google Code with ID 71

    Minify version: 2.1.1
    PHP version: 5.2.6
    jQuery 1.2.6-min.js
    tinyMCE 3.2.1
    
    What steps will reproduce the problem?
    1. /min?f=js/jquery.js,js/tiny_mce/tiny_mce.js,js/init.js&debug=1
    2. in init.js i have tinyMCE.init({ ... standard methods to initiate TinMCE
    ... });
    
    Expected output: correct one
    
    Actual output: JS ERROR (Firebug output):
    missing ; before statement
    [Break on this error] /* 28 *|
    xhr.open(type,s.url,s.async);tr...[s.url]=modRes;if(!jsonp)success();}else
    
    Did you run the unit tests? Did any FAIL? All went OK
    
    Please provide any additional information below.
    Sometimes 301 Moved permamently repeats with this request and never stops
    making browser to hang and request never ends
    

    Reported by popec82 on 2008-11-26 12:01:28

    Priority-Low Type-Defect Status-WontFix 
    opened by mrclay 15
  • Easier API for page minification

    Easier API for page minification

    Originally reported on Google Code with ID 129

    I've studies the Minify builder a little, but couldn't make much of the way 
    the html is minified.
    
    A nice way would be the following, where Minify would follow the config.
    <?php ob_start(); ?>
    <!-- html -->
    
    <?
    $contents = 0b_get_contents();
    ob_end_clean();
    require '/min/Minify.php';
    Minify::serve('Page', $contents);
    // This as a cleaner alternative to http://code.google.com/p/minify/source/browse/trunk/min/builder/index.php
    

    Reported by Kramieb on 2009-08-04 12:58:38

    Type-Enhancement Priority-High Status-Started 
    opened by mrclay 13
  • Incorrect CSS image paths

    Incorrect CSS image paths

    Originally reported on Google Code with ID 82

    Minify version: 2.1.1
    PHP version:5.2.4-2ubuntu5.4
    
    What steps will reproduce the problem?
    1. Create a css file with a relative image path in it for a background,
    such as:
    *****
    url("../images/fieldset-bg.gif") 
    *****
    2. Minify the css files with a relative image path in it :
    array(
            '//styles/somefile.css'
    );
    
    2. Compare the re-written image path in the compressed file:
    
    Expected output:
    original: "../images/fieldset-bg.gif"
    modified: "../images/fieldset-bg.gif"
    
    Actual output:
    
    original: "../images/fieldset-bg.gif"
    modified: "/../images/fieldset-bg.gif" 
    
    Did any unit tests FAIL?
    
    Running test_all.php produces the following failures:
    *****
    !FAIL: Minify_Cache_File : store (1 of 10 tests run so far have failed)
    !FAIL: Minify_Cache_File : isValid (2 of 12 tests run so far have failed)
    !FAIL: Minify_Cache_File : display (3 of 13 tests run so far have failed)
    !FAIL: Minify_Cache_File : fetch (4 of 14 tests run so far have failed)
    !FAIL: Minify_Cache_File : store w/ lock (5 of 15 tests run so far have failed)
    !FAIL: Minify_Cache_File : isValid (6 of 17 tests run so far have failed)
    !FAIL: Minify_Cache_File : display w/ lock (7 of 18 tests run so far have
    failed)
    !FAIL: Minify_Cache_File : fetch w/ lock (8 of 19 tests run so far have failed)
    !FAIL: environment : PHP/server does not auto-HTTP-encode content (9 of 60
    tests run so far have failed)
    *****
    
    Please provide any additional information below.
    
    This issue was discussed in brief here:
    http://groups.google.com/group/minify/browse_thread/thread/895cb58e4bbfe17
    
    
    

    Reported by bmharris on 2009-01-26 21:16:02

    Priority-High Status-Fixed Type-Defect 
    opened by mrclay 13
  • lack of includes support for less processor

    lack of includes support for less processor

    3.0 has support for serving .less files via Minify_LessCssSource which supports correct handling of getLastModified

    however, when using Minify_HTML_Helper::getUri the instances to Minify_LessCssSource are not made in setGroup and as a result _lastModified is set to main .less file, not the one of included one.

    @mrclay how do you suggest to solve this shortcoming?

    for serving, this is done in SourceFactory

    opened by glensc 12
  • closure-compiler-httpserver

    closure-compiler-httpserver

    I found that I have published closure-compiler-httpserver at some point:

    • https://github.com/glensc/closure-compiler-httpserver

    its purpose is to keep the java VM loaded, not execute java for every compile call, resulting in faster response and less CPU usage.

    I've never used it myself in production, but the code seems complete.

    Now the question: where to add a document about it?

    opened by glensc 0
  • Option to remove source mapping URLs from JS files or modify the path

    Option to remove source mapping URLs from JS files or modify the path

    Is there a way to remove to remove the source mapping URLs from the JS files? In the dev console I get the errors that the source map cannot be found. Another solution would be to modify the source mapping URLs in the JS files. Thank you very much for this library. Any thoughts on this issue?

    opened by AgentSmith0 0
  • PHP 8.1 uses HTML parsing functions in other way

    PHP 8.1 uses HTML parsing functions in other way

    See: https://www.php.net/manual/en/function.htmlspecialchars.php

    8.1.0 | flags changed from ENT_COMPAT to ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401.

    https://github.com/mrclay/minify/blob/master/lib/Minify.php#L474

    opened by panvid 0
  • Custom minifiers are not applied in

    Custom minifiers are not applied in "static" mode

    This line, written in config.php $min_serveOptions['minifiers'][Minify::TYPE_JS] = 'someCustomMinifier'; has no effect when requesting files in Static mode

    That is, the custom minifier for such a request does not work: https://example.com/min/static/0/f=min/quick-test.js

    But the minifier works for such a request: https://example.com/min/f=min/quick-test.js

    * Naturally, I cleaned the cache, deleted "static" files, it does not help.

    Can you please tell me how to make a custom minifier work in Static mode?

    opened by DmitrySpace 0
  • Problème d'affichage après changement d'hebergement.

    Problème d'affichage après changement d'hebergement.

    Bonjour, Je n'arrive pas à trouver d'où vient le problème, que ce soit en local ou sur le nouveau hebergement, j'ai un problème d'affichage, on dirait que mon site n'arrive plus à récupérer js + css. Pourriez vous m'apporter de l'aide svp? Capture d’écran 2021-07-08 144607 Capture d’écran 2021-07-08 144539

    opened by Patochedu64 0
Releases(3.0.4)
Owner
Steve Clay
Steve Clay
The Asset component manages URL generation and versioning of web assets such as CSS stylesheets, JavaScript files and image files.

Asset Component The Asset component manages URL generation and versioning of web assets such as CSS stylesheets, JavaScript files and image files. Res

Symfony 2.9k Jan 5, 2023
Commenting program developed with Html & Css & Php JavaScript Languages ​​and MySql

CommentSystem [BETA] Commenting program developed with Html & Css & Php JavaScript Languages and MySql How does it work ? After you set up your Databa

Azad 0 May 19, 2022
Middleware to minify the Html, CSS and Javascript content using wyrihaximus/compress

middlewares/minifier Middleware to minify the Html, CSS and Javascript content using wyrihaximus/compress and the following compressors by default: wy

Middlewares 15 Oct 25, 2022
A fast Javascript minifier that removes unnecessary whitespace and comments

js-minify A fast Javascript minifier that removes unnecessary whitespace and comments Installation If you are using Composer, use composer require gar

Patrick van Bergen 5 Aug 19, 2022
Assets Manager for "Vitewind" Theme, will inject CSS and JS assets for "Vitewind" theme to work properly with viteJS in development and production

Vitewind Manager plugin ?? Windi CSS and ⚡️ Vite, for ?? OctoberCMS & ❄️ WinterCMS Introduction This is a helper plugin for ?? Vitewind theme, don't i

Adil Chehabi 4 May 29, 2022
Javascript Minifier built in PHP

JShrink JShrink is a php class that minifies javascript so that it can be delivered to the client quicker. This code can be used by any product lookin

Tedious Developments 678 Dec 31, 2022
PHP class to generate bookmarklets from Javascript code

Bookmarklet Gen Convert readable Javascript code into bookmarklet links Features removes comments compresses code by removing extraneous spaces, but n

྅༻ Ǭɀħ ༄༆ཉ 13 Oct 5, 2022
An asset compression plugin for CakePHP. Provides file concatenation and a flexible filter system for preprocessing and minification.

Asset Compress Asset Compress is CakePHP plugin for helping reduce the number of requests, and optimizing the remaining requests your application make

Mark Story 367 Jul 20, 2022
GLPI is a Free Asset and IT Management Software package, Data center management, ITIL Service Desk, licenses tracking and software auditing.

GLPI stands for Gestionnaire Libre de Parc Informatique is a Free Asset and IT Management Software package, that provides ITIL Service Desk features, licenses tracking and software auditing.

GLPI 2.9k Jan 2, 2023
Put your assets into the pipe and smoke them.

Pipe Put your assets into the pipe and smoke them. Pipe is an asset pipeline in the spirit of Sprockets. It's meant as the practical way for managing

Christoph Hochstrasser 121 May 5, 2021
NotrinosERP is an open source, web-based enterprise management system that written in PHP and MySql.

NotrinosERP is an open source, web-based enterprise management system that written in PHP and MySql. NotrinosERP contains all the required modules for running any small to medium size businesses. It supports multi users, multi currencies, multi languages

Phương 56 Dec 20, 2022
JShrink is a php class that minifies javascript so that it can be delivered to the client quicker

JShrink JShrink is a php class that minifies javascript so that it can be delivered to the client quicker. This code can be used by any product lookin

Tedious Developments 677 Nov 16, 2022
A Parser for CSS Files written in PHP. Allows extraction of CSS files into a data structure, manipulation of said structure and output as (optimized) CSS

PHP CSS Parser A Parser for CSS Files written in PHP. Allows extraction of CSS files into a data structure, manipulation of said structure and output

Raphael Schweikert 1.6k Jan 5, 2023
The Asset component manages URL generation and versioning of web assets such as CSS stylesheets, JavaScript files and image files.

Asset Component The Asset component manages URL generation and versioning of web assets such as CSS stylesheets, JavaScript files and image files. Res

Symfony 2.9k Jan 5, 2023
Catches mail and serves it through a dream.

MailCatcher Catches mail and serves it through a dream. MailCatcher runs a super simple SMTP server which catches any message sent to it to display in

Samuel Cochran 5.8k Jan 5, 2023
A simple tool that I share with you. This tool serves to make conversions from text to audio Google Translate.

A simple tool that I share with you. This tool serves to make conversions from text to audio Google Translate. You can download this conversion 100% for free. Good luck.

Afid Arifin 1 Oct 25, 2021
Created simple login system and chat type website using mysql database along with php and html , css and javascript.

Created simple login system and chat type website using mysql database along with php and html , css and javascript.

null 1 Jan 6, 2022
A PHP Command Line tool that makes it easy to compile, concat, and minify front-end Javascript and CSS/SCSS dependencies.

Front End Compiler A PHP Command Line tool that makes it easy to compile, concat, and minify front-end Javascript and CSS/SCSS dependencies. The minif

Happy Medium 2 Nov 12, 2021
Complete Login and Registration system using HTML, CSS, JAVASCRIPT, BOOTSTRAP, PHP and MYSQL

Complete Login and Registration system using HTML, CSS, JAVASCRIPT, BOOTSTRAP, PHP and MYSQL

JehanKandy 11 Jul 13, 2022
Commenting program developed with Html & Css & Php JavaScript Languages ​​and MySql

CommentSystem [BETA] Commenting program developed with Html & Css & Php JavaScript Languages and MySql How does it work ? After you set up your Databa

Azad 0 May 19, 2022