Remove All Unwanted js and css files from theme I create a website based on Drupal. When I look at the JavaScript and CSS files loaded from Drupal, I see many unwanted files loaded. I want to force Drupal to load only those files added to the .info file and remove everything else. I think I can achieve it by using hook_js_alter() but I want to know if there is a better solution.
Drupal only has one sanctioned mechanism for removing specific assets, regardless of the motivation for doing so.

For CSS:

hook_css_alter

For JS:

hook_js_alter

To remove all style and scripts except .info style and script use below codes:     

function hook_css_alter(&amp;$css) {
    $themes=list_themes();
          foreach($css as $key=&gt;$item) {
            if (!in_array($key, $themes['yourthemename']-&gt;stylesheets['all'])) {
                unset($css[$key]);
            }
        }
}



function hook_js_alter(&amp;$js) {
    $themes=list_themes();
    foreach($js as $key=&gt;$item) {
        if (!in_array($key, $themes['yourthemename']-&gt;scripts)) {
            unset($js[$key]);
        }
    }
}


If the theme/module is custom, then obviously you can just remove the offending code manually if that makes more sense.