A fast Javascript minifier that removes unnecessary whitespace and comments

Overview

js-minify

A fast Javascript minifier that removes unnecessary whitespace and comments

Installation

If you are using Composer, use

composer require garfix/js-minify

Use

The simplest use of the library comes down to this:

$minifiedJs = \Garfix\JsMinify\Minifier::minify($js);

Where $js contains the unprocessed code and $minifiedJs holds the minified version.

If you want to change the default options, use minify($js, $options), where $options is an array of one or more of the following:

  • \Garfix\JsMinify\Minifier::FLAGGED_COMMENTS (bool, default: true) When set to false, /*! ... */ flagged comments are removed as well.

Background

I started this library because I believed JShrink could be made much faster by the use of dedicated regular expressions. This turned out to be true. It is about 10x faster on PHP 7 and 5x faster on PHP 8.

You might also like...
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 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

This composer plugin removes unnecessary development files and directories from vendor directory

Composer Vendor Cleaner This composer plugin removes unnecessary development files and directories from vendor directory. Installation Local installat

Victor The Cleaner for Composer - This tool removes unnecessary files and directories from Composer vendor directory.

Victor The Cleaner for Composer This tool removes unnecessary files and directories from Composer vendor directory. The Cleaner leaves only directorie

Removes whitelisted unnecessary files (like tests/docs etc.) from vendor directory

Composer vendor cleanup This is a simple script for the Composer to remove unnecessary files (documentation/examples/tests etc.) from included vendor

Laravel-comments-livewire - Livewire components for the laravel-comments package
Laravel-comments-livewire - Livewire components for the laravel-comments package

Associate comments and reactions with Eloquent models This package contains Livewire components to be used with the spatie/laravel-comments package. S

Rah comments - Paginated article comments list for Textpattern CMS

rah_comments Download | Packagist | Issues | Support forum | Donate Rah_comments lets you to paginate Textpattern CMS’ comment lists, splitting the lo

Laravel comments - This package enables to easily associate comments to any Eloquent model in your Laravel application

Laravel comments - This package enables to easily associate comments to any Eloquent model in your Laravel application

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

Html Minifier adalah paket simpel untuk minify output Html, Css style, dan Javascript sebelum dirender ke browser untuk aplikasi Laravel anda.
Html Minifier adalah paket simpel untuk minify output Html, Css style, dan Javascript sebelum dirender ke browser untuk aplikasi Laravel anda.

Laravel Html Minifier Adalah Paket simpel untuk minify HTML, Css Style, dan Javascript sebelum dirender ke browser untuk aplikasi Laravel anda. Alat i

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

Simplifies writing DocBlock comments in Javascript, PHP, CoffeeScript, Actionscript, C & C++
Simplifies writing DocBlock comments in Javascript, PHP, CoffeeScript, Actionscript, C & C++

DocBlockr DocBlockr is a package for Sublime Text 2 & 3 which makes writing documentation a breeze. DocBlockr supports JavaScript (including ES6), PHP

:clamp: HtmlMin: HTML Compressor and Minifier via PHP

🗜️ HtmlMin: HTML Compressor and Minifier for PHP Description HtmlMin is a fast and very easy to use PHP library that minifies given HTML5 source by r

A simple HTML minifier for Laravel 5, 6 & 7.

Laravel HTMLMin Laravel HTMLMin is currently maintained by Raza Mehdi, and is a simple HTML minifier for Laravel. It utilises Mr Clay's Minify package

A simple HTML minifier for Laravel 5, 6 & 7.

Laravel HTMLMin Laravel HTMLMin is currently maintained by Raza Mehdi, and is a simple HTML minifier for Laravel. It utilises Mr Clay's Minify package

Laravel HTMLMin - a simple HTML minifier for Laravel

Laravel HTMLMin Laravel HTMLMin is currently maintained by Raza Mehdi, and is a simple HTML minifier for Laravel. It utilises Mr Clay's Minify package

Removes final keywords from source code on-the-fly and allows mocking of final methods and classes

Removes final keywords from source code on-the-fly and allows mocking of final methods and classes. It can be used together with any test tool such as PHPUnit or Mockery.

TYPO3 CMS extension which checks used CSS selectors in HTML output of the current page and removes CSS declarations which are unused.

EXT:css_coverage TYPO3 CMS extension which checks used CSS selectors in HTML output of the current page and removes CSS declarations which are unused.

Compares two directories and removes the duplicate files from the second directory.

How does the HRZ Duplicate Refiner work? 1- Compares two directories : patternDir: the directory used as the pattern & does not change. victimDir: A d

Simply removes the applcation's front-end and redirects it to the admin area.

Simply removes the application's front-end and redirects it to the admin area.

Comments
  • Possibly add a `mangle` option?

    Possibly add a `mangle` option?

    This task might be a decent amount of work but maybe not. The UglifyJS node module has a mangle option that changes variable names and stuff like that so that they are shorter (thus saving precious bytes of space and bandwidth).

    So for example:

    (function () {
      var hi = 'Hello World'
    
      function hello () {
        console.log(hi)
      }
    
      hello()
    })()
    

    Becomes:

    !function(){var o="Hello World";console.log(o)}();
    

    With the mangle option set to true.

    opened by kodie 2
  • Newlines are still being preserved after the end of a function

    Newlines are still being preserved after the end of a function

    This was also an issue with JShrink: https://github.com/tedious/JShrink/issues/87 and is actually how I came across your issue related to that here: https://github.com/tedious/JShrink/issues/105

    But I'm still seeing this issue with js-minify.

    For example:

    function hello () {
      console.log('Hello World')
    }
    
    console.log('yay')
    

    Should become:

    function hello(){console.log('Hello World')}console.log('yay')
    

    But currently it becomes:

    function hello(){console.log('Hello World')}
    console.log('yay')
    
    opened by kodie 3
  • Add missing semicolons so that unnecessary newlines can be removed

    Add missing semicolons so that unnecessary newlines can be removed

    I found this package through JShrink and love the changes you've made. One small issue I've found is that if a line doesn't end with a semicolon, the newline is preserved, which is what you'd usually want, however, I typically write JavaScript using the Standard Style which doesn't use unnecessary semicolons, which works fine when you're adding a newline, but when minifying you'd want those semicolons added in so that the newline can be removed.

    So for example:

    var hi = 'Hola'
    
    function hello () {
      console.log('Hello World')
    }
    

    Should become:

    var hi='Hola';function hello(){console.log('Hello World')}
    

    But currently, it becomes:

    var hi='Hola'
    function hello(){console.log('Hello World')}
    

    The goal should be to have the entire JavaScript put onto one line.

    The UglifyJS node module does this, it would be nice if js-minify did too. I might look into the uglify source and see how they do it and submit a pull request when I have time.

    Thank you!

    opened by kodie 2
Releases(1.0.0)
Owner
Patrick van Bergen
Patrick van Bergen
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
Combines. minifies, and serves CSS or Javascript files

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 c

Steve Clay 3k Jan 7, 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
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
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
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
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