Remove unnecessary JS in Drupal


Drupal 6

function mytheme_preprocess_page(&$vars){
    $scripts = drupal_add_js();
    //PRINT THIS ARRAY AND UNSET THE UNWANTED ARRAY// 
    unset($scripts['module']['YOUR_PATH_TO_JS']);
    $vars['scripts']= drupal_get_js('header', $scripts);
}

Drupal 7

function mymodule_js_alter(&$javascript){
  $alias = drupal_get_path_alias($_GET['q']);
  if($alias =="my-page"){
    unset($javascript['sites/all/modules/mymodule/mymodule.js']);
  }
  unset($javascript['sites/all/modules/mymodule/mymodule.js']);
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s