ConcatHelper

Filepath: phork/php/utilities/ConcatHelper.class.php

The ConcatHelper class builds the HTML to include the concatenated and potentially minified CSS and Javascript files for improved load times. The URLs generated by this object are routed through the ConcatController included in the phork/sites/standard/controllers/ directory.

If the no concat flag is set this just outputs a tag for each file. There are two ways to set the no concat flag. The first is in the site configuration file by setting $arrConfig['NoConcat'] to false. The second way, just for testing purposes, is to add raw=1 to the query string.

In order to set up the correct routing for the concatenated file output the following routing line needs to be added to the site configuration file.

$arrConfig['Routes']['^/concat/(css|js)/([0-9]*)/([^/]*)/[a-z]+.(css|js)$'] = '/concat/$1/version=$2/files=$3/';

The version number in the routed URL is used for cache busting for both the application's internal cache and the users' browser cache. Any time a change is made to a CSS or JS file that's run through the concatenator it's a good idea to increment the version number in the site configuration file. The version number is stored in the $arrConfig['CssVersion'] and $arrConfig['JsVersion'] variables.

Minification

The recommended Javascript minifier is Yahoo's YUI Compressor and the recommending naming convention is to add a .min extension (eg. yourscript.min.js).


Example

AppLoader::includeUtility('ConcatHelper');
$objConcatHelper = new ConcatHelper();

print $objConcatHelper->css(array(
    "{$strCssUrl}/css/common/global.css",
    "{$strCssUrl}/css/themes/{$strTheme}/global.css"
), 'screen');

print $objConcatHelper->js(array(
    "{$strJsUrl}/js/common/global.js",
    "{$strJsUrl}/js/common/select.js"
);