Note that there are some explanatory texts on larger screens.

plurals
  1. PODrupal 6 & 7 unset Javascript from header
    text
    copied!<p>EDIT: My question applies to Drupal 6 &amp; 7, though my code example is Drupal 6. People have provided answers are useful for both versions of Drupal.</p> <p>I'm currently working in Drupal creating a mobile theme for a Drupal 6 website and trying to remove all unnecessary core and module JavaScript and css through the <code>preprocess_page</code> function in my template.php file. The css files are successfully removed, but I can't seem to get the JavaScript to be removed. Here's what I've got. In this example, everything is successfully removed except for the the ajax scripts.</p> <p>Any idea what I'm doing wrong?</p> <pre><code>&lt;?php function mytheme_preprocess_page(&amp;$vars) { //////// remove unneccesary drupal head files for mobile version // CSS $css = drupal_add_css(); // core unset($css['all']['module']['modules/user/user.css']); unset($css['all']['module']['modules/node/node.css']); unset($css['all']['module']['modules/system/defaults.css']); unset($css['all']['module']['modules/system/system.css']); unset($css['all']['module']['modules/system/system-menus.css']); // contributed -- automatically generate the path—— just easier this way $rm[] = drupal_get_path('module','filefield').'/filefield.css'; $rm[] = drupal_get_path('module','flickr').'/flickr.css'; $rm[] = drupal_get_path('module','logintoboggan').'/logintoboggan.css'; $rm[] = drupal_get_path('module','logintoboggan').'/logintoboggan.css'; $rm[] = drupal_get_path('module','fieldgroup').'/fieldgroup.css'; $rm[] = drupal_get_path('module','views').'/css/views.css'; $rm[] = drupal_get_path('module','content').'/theme/content-module.css'; // remove the contribs from the array foreach ($rm as $key =&gt; $value) { unset($css['all']['module'][$value]); } // JAVASCRIPT $scripts = drupal_add_js(); unset($scripts['module']['sites/all/modules/ajax/ajax.js']); unset($scripts['module']['sites/all/modules/ajax/jquery/jquery.a_form.packed.js']); // recreate the tempalate variables $vars['styles'] = drupal_get_css($css); $vars['scripts'] = drupal_get_js('header', $scripts); } ?&gt; </code></pre> <p>ETA: Here is the way the scripts print out in the header:</p> <pre><code>&lt;script type="text/javascript" src="/sites/all/modules/ajax/jquery/jquery.a_form.packed.js?P"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="/sites/all/modules/ajax/ajax.js?P"&gt;&lt;/script&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload