0

I'm trying to remove all javascript for anonymous users but I've hit a roadblock.

This is the php I'm using in template.php (phptemplate_preprocess_page function):

$js = drupal_add_js();
unset($js['core']);
unset($js['module']);
unset($js['setting']);

$vars['scripts'] = $js;

print_r($vars['scripts']); // prints what it should
print_r(drupal_add_js('header', $js));  // prints everything like nothing happened!

2 Answers 2

0

You can do it in function phptemplate_preprocess_page exists in template.php

The below is code to remove unwanted js

function phptemplate_preprocess_page(&$vars) {

  $scripts = drupal_add_js();
  //PRINT THIS ARRAY AND UNSET THE UNWANTED ARRAY
  // unset($scripts['module']['sites/default/files/js/jquery-min.js']);
  unset($scripts['module']['YOUR_PATH_TO_JS']);
  $vars['scripts'] = drupal_get_js('header', $scripts);  

}
5
  • Yes thank you, I already have that in that function. Commented Feb 29, 2012 at 12:55
  • ok, then it should work! Did you enabled page cache or js aggregation? Commented Feb 29, 2012 at 13:13
  • Cache and aggregation is disabled. It definitely should work so any ideas are welcome! Commented Feb 29, 2012 at 13:29
  • Ok, check in your page.tpl.php print $scripts; present or not.Then Clear your cache again.Check that , drupal is calling this function or not? Commented Feb 29, 2012 at 14:31
  • It is printing $scripts normally and I've tried clearing the cache several times. And yes, Drupal is calling the script. I'm beginning to think this is quite strange. Commented Feb 29, 2012 at 15:08
0

I've found the problem. It seems that the JQuery Update module is the culprit, more specifically the jquery_update_theme_registry_alter function:

  • Make jQuery Update's page preprocess function run after everything else's,
  • so that a theme can't call drupal_get_js() and mess everything up. */

I will discuss this with the Jquery update module makers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.