m64253 edited this page Sep 13, 2010 · 16 revisions
Clone this wiki locally

Welcome to the ComboLoader wiki, a PHP class for combining and minifying javascript and css!

This is something a have built just for the fun of it, heavily inspired by YUI php loader. Uses the YUI Compressor and, optionally, Google Closure.

Usage examples
Ex 1: Using the request_uri, probably works in most cases
new ComboLoader($_SERVER['REQUEST_URI'][, array('use_cache' => true)]);

Ex 2: Using the auto method to detect what works
$comboLoader = new ComboLoader([array('use_cache' => true)]);

Ex 3: Using the handle method and also doing some config
$comboLoader = new ComboLoader();
$comboLoader->setOption('use_cache', true);

Example 1
Lets say your host is name combo.com and a request comes looking like this:
The files that will be served are all the ones from the “version/Component-A/Scripts” directory and “version/Component-B/Scripts/a-js-file.js”.

“version/Component-A.js” means load all files in the “Scripts” of that component.
“version/Component-B/a-js-file.js” means just load the single “a-js-file.js” in that components “Scripts” directory.
And of course you could also request the file by the full path ex. “version/Component-B/Scripts/a-js-file.js”, but who wants to write more?

So by requesting a .js-file the ComboLoader knows that the file it will be looking for is located in the “Scripts” directory of that component.

Example 2
The request:
The same files are loaded as in example 1 but here we are setting the version as a global for all files requested, even less to write, yay :D
Note: You can still request a different version by prepending the version to a single param.

js_directory_name Default: Scripts If a .js-file look for it here
css_directory_name Default: Styles If a .css-file look for it here
assets_path Default: Assets The root directory
cache_path Default: /tmp The combined and minified file are stored here
yui_compressor_path Default: blank Set this in order to be able to use the YUI compressor
version_pattern Default: [0-9]+ A simple pattern to figure out what part is the version
js_content_type Default: application/x-javascript .js-files will be served with this content-type
css_content_type Default: text/css .css-files will be served with this content-type
use_cache Default: false Set to true to enable caching of served files
minify Default: true Set to false to disable minification of served files
js_minifier Default: YUI Possible values are YUI or Closure

Assets structure

  • Assets The place where all your file are
    • Version A subfolder per version
      • Components A Components folder that hold all your different componets
        • Component-A Name of a component
          • Styles
          • Scripts
          • etc.
        • Component-B
          • Styles
          • Scripts
          • etc.
        • Component-C
          • Styles
          • Scripts
          • etc.
        • etc.