I was looking for a way to combine all my CSS and JS files to reduce http requests so I decided to write this plugin. It takes all the provided files and combines them into 1 file and performs some minification on them.
It also has the option to gzip your files.
If you have any issues you can leave a comment on my blog or send me an .(JavaScript must be enabled to view this email address).
------------------------------
- Requirements
------------------------------
ExpressionEngine 2.x
PHP 5+
JavaScriptPacker (included) - Needed for minification of Javascript files.
------------------------------
- Parameters
------------------------------
type = js/css (defaults to css)
assets(required) = '|' delimited list of asset file names
asset_dir(required) = relative path from the root to the directory where your assets are
cache_name = a name for the cached file
output = tag/code/disable (defaults to tag) Tag outputs a link/script tag to the cache file, code outputs the combined and minified code and disable outputs tags linking to the original files
minify = on/off (defaults to on)
gzip = on/off (defaults to off)
------------------------------
- Example Usage
------------------------------
There are 2 ways to use this plugin
The first way is to put the template tag into your <head> like:
{exp:asset_linker type="js" assets="jquery|cufon|Calibri.font|slideshow|common" asset_dir="/assets/js" cache_name="scripts"}
{exp:asset_linker type="css" assets="reset|960|text|master" asset_dir="/assets/css" cache_name="home"}
-- Example 2 --
The second option is to put the tags into a template which you then link to:
in your template
<link rel="stylesheet" type="text/css" media="all" href="/index.php/site/styles/" />
in 'site/styles' CSS template
{exp:asset_linker type="css" assets="reset|960|text|master" asset_dir="/assets/css" cache_name="home" output="code"}
-- Notes --
The second option lets you use ExpressionEngine's output system to have everything gzipped and use the page cache but experienced lower performance in my test and is not recommended for most cases.
------------------------------
- Changelog
------------------------------
1.1 - Added output="disable" option (Thanks to Kevin Smith)
- Don't add the gzip php code if output="code"
1.0 - Initial Release