📜 ⬆️ ⬇️

How to cut unnecessary css and js inclusions from Drupal themes (6.x versions)

Hello, habra-comrades!

I often come across messages that Drupal themes are always hampered by the extra drupal css inclusions (files like system.css, defaults.css, node.css), which affect the already prepared styles and interfere with the life of the layout makers.

Actually, I’ll tell you how to get rid of these inlays correctly (the solution is not suitable for those who for some reason prefer to see the admin panel in the subject of the site - don’t even proceed to these actions !!!).

To begin, open the file template.php , which is in the right topic.
')
Then add the following code to your heart's mind (replace YOURFUNCTIONNAME with the name of your theme):

function YOURFUNCTIONNAME_preprocess_page(&$vars) {

if( request_uri() != '/admin/build/block' ){

// css
$css = drupal_add_css();

//
unset($css['all']['module']['modules/system/system.css']);
unset($css['all']['module']['modules/system/defaults.css']);
unset($css['all']['module']['modules/system/system-menus.css']);
unset($css['all']['module']['modules/node/node.css']);
unset($css['all']['module']['modules/views/css/views.css']);

//
$vars['styles'] = drupal_get_css($css);

}

}


That's all - unnecessary unnecessary styles do not slow down the page loading and it's easier for their styles to find the right way to the user's eyes. The condition " if (request_uri ()! = '/ Admin / build / block') {} " is here so that the block editing page (which, although part of the admin panel, is still displayed in the site design) remains necessary for work functional.

Since we cut the css, then we will similarly take on JavaScript inclusions. In the same function YOURFUNCTIONNAME_preprocess_page add:
if(drupal_is_front_page()){

// jQuery
drupal_add_js('misc/jquery_new.js');

// JS
$js = drupal_add_js();

// jQuery
unset($js['core']['misc/jquery.js']);

// JS
$vars['scripts'] = drupal_get_js('header', $js);

}


This is how you can easily get rid of the regular JS jQuery call of a bearded 1.2.6 version from 2008 on the main page (I needed to do a lot of complicated JS on the main page, which did not work with the old jQuery version and so I easily and easily substitution).

Be careful with cutting out JS - don't ruin Drupal's functionality :)

That's all! I hope this is useful to someone.

UPDATE On the advice of Anonym and Razunter, if you just need to update the jQuery version, it is better to use the patch or the jQuery Update module. In the case of manual cutting JavaScript inclody problems may arise.

Source: https://habr.com/ru/post/87497/


All Articles