A set of Zend Framework view helpers that automagically bundle, minify, and compress your javascript and css.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



Bundle-phu is a set of Zend Framework view helpers that automagically concatenate, minify, and gzip your javascript and stylesheets into bundles. This reduces the number of HTTP requests to your servers as well as your bandwidth.

Bundle-phu is inspired by bundle-fu a Ruby on Rails equivalent.

Bundle-phu automatically detects modification to your JS/CSS and will regenerate bundles automatically. Minification can be done using either an external program such as the YUI compressor or using PHP via callback.

Compression is done using PHP's gzencode() function.


<script type="text/javascript" src="/js/jquery.js"></script>
<script type="text/javascript" src="/js/foo.js"></script>
<script type="text/javascript" src="/js/bar.js"></script>
<script type="text/javascript" src="/js/baz.js"></script>
<link media="screen" type="text/css" href="/css/jquery.css" />
<link media="screen" type="text/css" href="/css/foo.css" />
<link media="screen" type="text/css" href="/css/bar.css" />
<link media="screen" type="text/css" href="/css/baz.css" />


<script type="text/javascript" src="bundle_3f84da97fc873ca8371a8203fcdd8a82.css?1234567890"></script>
<link type="text/css" src="bundle_3f84da97fc873ca8371a8203fcdd8a82.css?1234567890"></script>


  1. Place the BundlePhu directory somewhere in your include_path:

     |-- application
     |-- library
     |   `-- BundlePhu
     |-- public
  2. Add the BundlePhu view helpers to your view's helper path, and configure the helpers:

     class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
         protected function _initView()
             $view = new Zend_View();
                 PATH_PROJECT . '/library/BundlePhu/View/Helper',
                 ->setCacheDir(PATH_PROJECT . '/data/cache/js')
                 ->setDocRoot(PATH_PROJECT . '/public')
                 ->setCacheDir(PATH_PROJECT . '/data/cache/css')
                 ->setDocRoot(PATH_PROJECT . '/public')
             $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
             return $view;
  3. Ensure your CacheDir is writable by the user your web server runs as

  4. Using either an Alias (apache) or location/alias (nginx) map the UrlPrefix to CacheDir. You can also do this using a symlink from your /public directory. e.g. /public/javascripts -> /../data/cache/js


As both these helpers extend from the existing HeadScript and HeadLink helpers in Zend Framework, you can use them just as you do those.

<? $this->bundleScript()->offsetSetFile(00, $this->baseUrl('/js/jquery.js')) ?>
<? $this->bundleScript()->appendFile($this->baseUrl('/js/foo.js')) ?>