I am using drupal 7 and created my custom theme. Now I am facing problem that page is containing extra line breaks and while spaces when I open view source.

Can some one suggest any module/code snippet which minimize my html so that page render fast.

Else tell me where I can minimize it in my template.php file or any .tpl file.

  • If your site is slow I really don't think your problem is whitespace in your html. It might make an extremely small difference. You can override all the template files on your site to remove all whitespace but it will make it extremely frustrating to ever have to do work in those templates later. – rooby Jan 29 '14 at 11:00
  • Make sure page caching & compression, along with css & js aggregation are all on, then if it is slow do some investigation as to why. Using browser plugins like the ff web developer toolbar gives you the ability to see a breakdown of how much data is being downloaded for scripts/images/etc. You can also try the xhprof module to look for bottle necks. Try some additional performance related modules or server config, maybe removing some unneeded modules, maybe modifying some database queries to make them faster, etc. – rooby Jan 29 '14 at 11:03

Agree with rooby, whitespace in html does not slow down the site performance.

You can use the Minify module to remove extra line breaks and whitespace before and after HTML tag.

Minify also minimize the JavaScript files. Minimized JavaScript files are smaller in size as compare to regular JavaScript files. Smaller size will helps you to load site faster.

To use Minify

  • Download and install minify module
  • Go to performace
  • Select minify HTML
  • To minify JavaScript files select Minify JavaScript files in upper right corner
| improve this answer | |
  • Thnaks, It help alot. It will remove HTML extra white space and Minify JS as well. It helps to reduce page load time. – Pranav Pathak Feb 5 '14 at 10:20

I agree with all the suggestions so far. One other way I handle the injection of p tags and
conversions is through the content authoring settings. If you're using Full HTML settings on the node, you can edit how Drupal handles line breaks by visiting the config page at Configuration > Content Authoring > Text Formats > Full HTML. Under the Cleanup and Output you could check the box to remove linebreaks.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.