# sfCombineFilter plugin The `sfCombineFilter` is an implementation of the [CSS and Javascript Combiner](http://rakaz.nl/extra/code/combine) by Niels Leenheer. It makes your pages load faster by combining and compressing javascript and css files. This filter provides means to automatically combine your included javascripts and stylesheets into one request each. All of the included files are combined into a single large file and compressed using gzip. The resulting file is cached and used every time that particular combination of files is used, until any of the files are changed at which point a new cache is automatically created. The symfony filter looks at all of the javascripts and stylesheets resources specified in the current response, and automatically creates a string that combines all of the names together. When your visitors request this special file, they will get one large file, gzipped and ready to go. For example, if you are including the following javascripts on every page: * /js/prototype.js * /js/builder.js * /js/effects.js * /js/dragdrop.js * /js/slider.js Using the combine script, you can combine all of these files into a single file by changing the URL to * /js/packed/prototype.js,builder.js,effects.js,dragdrop.js,slider.js The sfCombineFilter will do this automatically. Then, with the help of .htaccess and the included combine.php file in the /web folder, this request is routed to combine.php which uses the string of file names to either locate an existing cached file of the concatenated and compressed source or create a new one. ## Features * Support for automatic combination of javascript, css, or both * Support for script exclusions based on file path (mainly used when css relies on a particular path to load images) * Cache that refreshes automatically when source files are changed ## Installation [sh] symfony plugin-install http://plugins.symfony-project.com/sfCombineFilter ## Usage ### Enable the filter * In your app/config/filters.yml, add the sfCombineFilter. This must come AFTER "common": rendering: ~ web_debug: ~ security: ~ # generally, you will want to insert your own filters here cache: ~ common: ~ sfCombineFilter: class: sfCombineFilter param: javascripts: true stylesheets: true root_js_only: false root_css_only: true flash: ~ execution: ~ By default all javascripts and stylesheets requested in '/js-packed' or '/css-packed' respectively are combined into one request each, whereas files requested outside of that path are ignored. You can turn off the filter all together for javascript or css by setting those parameters to "false". If you want to include files requested from any path and not just those inside /js or /css, then set the parameters "root_js_only" and "root_css_only" to false. ### Modify .htaccess Add the following to your .htaccess rewrite rules: RewriteRule ^css/packed/(.*\.css) /sfCombineFilterPlugin/combine.php?type=css&files=$1 RewriteRule ^js/packed/(.*\.js) /sfCombineFilterPlugin/combine.php?type=javascript&files=$1 This will capture any requests made to /js/packed/* or /css/packed/* and route them through the compression script. ## Changelog ### 2007-07-26 | 0.1.0 beta Initial public release. ### 2007-08-02 | 0.1.1 beta Changes by Kiril Angov: * Fixes regular expression to match '^/css/' * Fixes issues when included files outside of root css and js directories. * New: Option to minify the js using JSMin.