Skip to content

angelahnicole/JShrink

 
 

Repository files navigation

JShrink for Laravel 4 Build Status

License Latest Stable Version Total Downloads

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 looking to minify their javascript on the fly (although caching the results is suggested for performance reasons). Unlike many other products this is not a port into php but a native application, resulting in better performance.

This has been tested on Laravel version 4.0, but it should work on version 4.1.

Default Usage

Minifying your code is simple call to a static function-

// Basic (default) usage.
$minifiedCode = JShrink::minify($js);

// Disable YUI style comment preservation.
$minifiedCode = JShrink::minify($js, array('flaggedComments' => false));

Results

  • Raw - 586,990
  • Gzip - 151,301
  • JShrink - 371,982
  • JShrink and Gzip - 93,507

Installing

Composer

In order for this to work with Laravel, you must install this via Composer. If you wish to install it another way, then I would recommend using tedivm's repository.

Until JShrink reaches a stable API with version 1.0 it is recommended that you review changes before even Minor updates, although bug fixes will always be backwards compatible.

{
    "repositories": [
        {
            ...	
            "type": "vcs",
            "url": "https://github.com/angelahnicole/JShrink"
            ...
        }
    ],
    "require": {
        ...
        "angelahnicole/jshrink": "dev-master"
        ...
    }
}

Laravel

To register JShrink with Laravel you must include it in the Autoloaded Service Providers array along with adding it to the list of Class Aliases.

// app/config/app.php
...
/*
|--------------------------------------------------------------------------
| Autoloaded Service Providers
|--------------------------------------------------------------------------
|
| The service providers listed here will be automatically loaded on the
| request to your application. Feel free to add your own services to
| this array to grant expanded functionality to your applications.
|
*/
  'providers' => array(
    ...
    'JShrink\JShrinkServiceProvider',
    ...
  )

...

/*
|--------------------------------------------------------------------------
| Class Aliases
|--------------------------------------------------------------------------
|
| This array of class aliases will be registered when this application
| is started. However, feel free to register as many as you wish as
| the aliases are "lazy" loaded so they don't hinder performance.
|
*/
	'aliases' => array( 
	  ...
	  'JShrink'         => 'JShrink\Minifier',
	  ...
	 )
...

Problems?

  • Make sure to perform a composer update in the command line after including it in your composer.json file.
  • You may have to perform a php artisan dump-autoload
  • You may also have to perform a composer dump-autoload

Github

Releases of JShrink (from tedivm) are available on Github.

License

JShrink is licensed under the BSD License. See the LICENSE file for details.

In the spirit of open source, use of this library for evil is discouraged but not prohibited.

About

Javascript Minifier built in PHP

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • PHP 81.5%
  • JavaScript 17.4%
  • Shell 1.1%