Use Google Closure Compiler to minify javascript files in Laravel 4.

Installs: 333

Dependents: 0

Stars: 2

Watchers: 2

Forks: 2

v1.2.5 2013-12-12 14:49 UTC


This Laravel4 package adds a view-helper javascript_compiled() to minimize a single javascript file or bundles of several javascript files. Everything is done using Google Closure Compiler.

Latest Stable Version Total Downloads Build Status Coverage Status


Install it via Composer by adding the following to your composer.json-file (the asterix can be changed to an exact version):

"jboysen/laravel-gcc": "1.*"

NOTE: if you get this error: zendframework/zend-http dev-master requires zendframework/zend-stdlib dev-master -> no matching package found., you might have got this error..

...and add the following to the providers-array in your app/config/app.php:



The config-file is self-explanatory: config.php

To change some of the settings, simply just run (as always) php artisan config:publish jboysen/laravel-gcc


View helper

The helper accepts either a string representing a single javascript file or an array representing several files (a bundle). A bundle will be compiled in the order given in the array.

Example #1:

// hello.blade.php
{{ javascript_compiled('default.js') }}

Example #2:

// hello.php
<?php echo javascript_compiled(array(
  )); ?>

This helper will:

  1. Lookup the files given as argument to the helper.
  2. Create a unique filename for the compiled files based on the filenames and the last modification time of the files.
  3. Compile the bundle (if it's not present).
  4. Output a script-tag linking to the compiled file.

artisan commands


As compilation of several files sometimes can take time, it is better to do this "offline", that is before any users hit the web application.

php artisan gcc:build

This command will scan all files in the /app/views-directory and find all uses of the view-helper described above, and compile the bundles immediately, making sure the users won't experience any long response times.


Remove all files from the /app/storage/laravel-gcc-folder. This task might be useful in deployment-procedures.