-
Notifications
You must be signed in to change notification settings - Fork 125
Home
Asset Compress is a plugin for CakePHP that can help you reduce the number of HTTP requests your application makes, as well as provide some nice sugar for Javascript and CSS files. Its partly intended as a way to get a 'build' stage without actually making the effort to write build scripts. By using directives you can resolve dependencies in Javascript and inline @import
statements in CSS files.
Download the plugin and place on one of your plugin paths. If you are using CakePHP 2.0, make sure to use the 2.0
branch. Before using the plugin with CakePHP 2.0, you'll need to load the plugin:
// in app/Config/bootstrap.php
CakePlugin::load('AssetCompress');
Depending on whether or not you use caching, you may need to create some additional directories in your webroot. Next up, you'll need a Configuration file before you can get started with AssetCompress.
- Configuration Configuring Asset Compress. Defining build files and plugin behaviour.
- Filters Filtering the concatenated output.
- Shell The asset compress shell, used for generating and clearing build files.
- Helper Usage Using the AssetCompress helper in your application.
- Troubleshooting WTF, and how you might be able to fix it.
After downloading the AssetCompress plugin and putting it in your applications plugins
directory, you should create your ini file. To start off with add the following to app/Config/asset_compress.ini
[General]
debug = true
[js]
paths[] = WEBROOT/js
[js_jquery-combined.js]
files[] = jquery.js
files[] = jquery.ui-core.js
If you were using jQuery and a few plugins, you could combine jQuery and the plugins you use into a single build file. Once you've added all your plugins with files[]
you can link the build file in your layout. But first, you'll need to add the helper. In your AppController add:
var $helpers = array('AssetCompress.AssetCompress');
Or add the AssetCompress helper to your existing helpers array. Next link the build file in your layout:
<?php echo $this->AssetCompress->script('jquery-combined'); ?>
After refreshing the page, you should get jQuery, and all your plugins as a single request.