Jettison
Categories
Component ID
Component name
Component type
Maintenance status
Development status
Component security advisory coverage
Downloads
Component created
Component changed
Component body
Jettison unwanted CSS and JavaScript files!
This module provides a hook-based mechanism for getting rid of unwanted CSS and JS files. Simply declare which files you want deleted, and this will take care of removing them.
There's also a nice administration interface that can be used for simple cases.
What is it good for?
Sometimes a module adds CSS or JS that you don't want (or don't want to show up on non-admin themes). Use Jettison to get rid of them.
Occasionally, modules put their CSS/JS on every page when it should really only be on a few isolated pages. A jettison hook can be used to detect the conditions and then remove strategically.
Examples
Say we have a module called Example, and we want to remove the foo.js that some other module adds. Here's how to accomplish this in Jettison's API:
function example_preprocess_page(&$vars) {
$icky_js = drupal_get_path('module', 'foo') . '/foo.js';
jettison_js($icky_js, 'module');
}
Or to remove a CSS file from some offending theme (yes, this would be an edge case), we can do this:
function example_preprocess_page(&$vars) {
$ugly_css = drupal_get_path('theme', 'ugly') . '/foo.css';
jettison_css($ugly_css, 'theme');
}
If your needs are more sophisticated than a simple removal, you might want to look into the following API functions:
// Alter the list of JS files before they are removed from a page
function hook_jettison_js_list_alter(&$list) {
// Remove an item from the jettison list:
unset($list['foo.js']);
}
// Same as above, but for CSS
function hook_jettison_css_list_alter(&$list) {
// Remove an item from the jettison list:
unset($list['foo.css']);
}
// Alter the JS after jettisons have been made, but before the
// data is shipped off to the page template.
function hook_jettison_js_postprocess_list_alter(&$list) {
}
// Alter the CSS after jettisons have been made, but before the
// data is shipped off to the page template.
function hook_jettison_css_postprocess_list_alter(&$list) {
}
Take a look at API.php (included in the module) for details.
Interoperability (and some technical details)
Jettison uses some elaborate tricks to get around the static anti-pattern that drupal_add_js() and drupal_add_css() use to store data. It is a trick employed by some other modules (notably jQuery update). We have done our best to remain compatible with such modules.
Should you find a module that is not compatible with Jettison because it manipulates the page template data, you can mend the situation with hook_jettison_js_postprocess_list_alter() and hook_jettison_css_postprocess_list_alter().
