Drupal remove white-space from HTML

Add this simple function into your theme’s template.php in order to strip out unnecessary whitespace and line breaks, saving a bit of file size where possible (I saved 17kb from my homepage). If a page contains a <pre> or <textarea> tag, it is left alone, as to not affect code blocks or text typed in a form.

 

Exclude Drupal system CSS for logged-out users

In your template.php, you can exclude Drupal’s system CSS files, or any CSS file that wasnt added by your theme (this includes CSS added by modules) using this PHP snippet:

 

Drupal homepage only CSS

So you want to have a base.css file on all pages, then a homepage.css file just for the homepage, and non-homepage.css for all other pages? Here’s how:

In your themes’ .info file, include the base.css file:

In your themes’ template.php file:

Note: In the code above I have chosen to inline the homepage only CSS.

 

Did you find this post useful?

Tip me some bitcoin: