3

What's the best way to remove white spaces on a site based on html, JavaScript and php. Is there some sort of way to configure Apache to automatically remove white spaces from all html, JavaScript returned to client?

Lightness Races in Orbit
  • 358,771
  • 68
  • 593
  • 989
Imran Omar Bukhsh
  • 7,221
  • 11
  • 54
  • 77
  • Probably not. Why do you need this? Extra whitespace doesn't impact load times much at all. – Bojangles Sep 15 '11 at 11:39
  • 5
    "Extra whitespace doesn't impact load times much at all" - Then why does everybody and their dog recommend that HTML, CSS and JS should be minified? – Clive Sep 15 '11 at 11:40
  • @Alfred: 50% is fine. Especially since many of his questions only have a single answer so far. – Lightness Races in Orbit Sep 15 '11 at 11:42
  • hmm..image you have a page that is of 28k in size. Now image you have a million people visiting your website. What if you were able to compress the file down to 25k. You save 3 kb on the file. Now multiply that with a million users. Thats 3,000,000 kb . Imagine how much you can save on your bandwidth and how many more users you can cater with that saved 3,000,000 kb on your bandwidth – Imran Omar Bukhsh Sep 15 '11 at 11:47
  • @Imran: Do you have a million people visiting your website? – Lightness Races in Orbit Sep 15 '11 at 11:49
  • 1
    why waste server CPU on processing your hosted files - IMHO you should strip unwanted whitespace yourself when you publish your document. A single regex should cover it. I don't like the idea of scripts processing and 'fixing' my code. If you let the server do this every time a page is served, that's a lot of wasted CPU power, especially if the same process is done a million times over and over - as per the unrealistic example above. – increddibelly Sep 15 '11 at 11:54
  • Whitespace in HTML can't be removed as it may be significant. It may become significant due to the CSS or Javascript, so an automated minifier won't be able to tell whether it is or not, just by looking at the HTML code. Therefore it's unlikely that you'll be able to minify your HTML in an automated way. Javascript and CSS have well documented minifying techniques, which is good to do, as long as you don't need to do any debugging on the code. – Spudley Sep 15 '11 at 11:56

1 Answers1

2

Take a look at mod_pagespeed which can do this and a lot more besides.

Also see this question for more on this topic.

Community
  • 1
  • 1
Paul Dixon
  • 277,937
  • 48
  • 303
  • 335