Jan 222013

Every now and again, someone in IRC wants to know how to completely remove javascript from Drupal 7. This isn’t necessarily a good idea – there’s a lot of little things in Drupal that use javascript, and you really don’t want to remove javascript from the admin side of the site as it won’t be anywhere as easy to use. However if you are quite sure that you really, really do want to remove javascript, you need the following code in your theme’s template.php.

function yourtheme_js_alter(&$javascript) {
    $javascript = array();
function yourtheme_html_tag($variables){
    $element = $variables['element'];
    if ($element['#tag'] == 'script') return "";
    return theme_html_tag($variables);

Make sure you change “yourtheme” to the name of your theme. Clear cache, and you’ll have no javascript. Note that this completely removes *all* javascript including the default jquery from all pages, and if you want to remove it only from select pages you’ll need to wrap the code in conditionals.