From where does the $scripts variable in drupal gets generated? I am getting an unwanted code generated in the html code like this

 <script type="text/javascript" src="/js/js_01770598d5388f7cbcfe786a6df4ef2a.js"></script>

I want to remove that code, for that I need to know the details about $scripts varialble used in tpl file

  • imho you need to be certain that the included js is actually unwanted before deciding to remove it, it might be any of the contributed modules that your site uses and could paralyze some functionality. If you are certain that the script is useless you could check this and this to aid your cause. Commented Jan 10, 2013 at 7:18
  • no, it is a malware
    – user7282
    Commented Jan 10, 2013 at 7:22
  • It it actually in the rendered output when you do a view source, or is it being dynamically added?
    – mpdonadio
    Commented Jan 10, 2013 at 15:21

1 Answer 1


You should start at template_preprocess_node() where the $scripts variable is initialised:

$variables['scripts'] = drupal_get_js();

Then have a look at drupal_get_js() and follow the functions from there to find out how that mechanism works.

Then have a look at any implementations of hook_page_alter() throughout your site, where the $vars['scripts'] variable might be being manipulated.

Even though that technically answers your question, I'd be surprised if you find what you're looking for there. I've never heard of any malware that specifically targets Drupal (which is what this would be if it's manipulating the $scripts variable).

I'd check the rest of your page source to see if there's some JS being injected somewhere which is adding that <script> tag to the <head> dynamically, just in case.

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.