1

Can some one give me reason why (or not) we create one line html?

That I know just reduce file size (benefit) but in server we must add some function to generate one line html (server cost) or we will have trouble when we need to change some code (editing cost).

Reinstar
  • 126
  • 1
  • 1
  • 20

2 Answers2

0

You shouldn't minify your HTML. It isn't worth the time and the work you will have to do when editing. Take a look at this very good answer.
You should optimize your CSS though. There's a free program: Scout, that checks for changes on your css files and creates a minified version of it automatically. It implements Sass, which will make coding CSS much easier. You should try it.

Community
  • 1
  • 1
Angel Yan
  • 950
  • 7
  • 10
0

You don't manually create HTML like that. Personally, my CMS caches it's output as static files to be served to the user. Before it caches, it runs:

$tocache is the contents of the page to be displayed. I do this, then write it to disk. Apache then serves the static content instead avoiding the DB and PHP on subsequent access.

// Remove white space
$tocache = str_replace(array("\n", "\t","\r")," ",$tocache);

// Remove unnecessary closing tags (I know </p> could be here, but it caused problems for me)
$tocache = str_replace(array("</option>","</td>","</tr>","</th>","</dt>","</dd>","</li>","</body>","</html>"),"",$tocache);

// remove ' or " around attributes that don't have spaces
$tocache = preg_replace('/(href|src|id|class|name|type|rel|sizes|lang|title|itemtype|itemprop)=(\"|\')([^\"\'\`=<>\s]+)(\"|\')/i', '$1=$3', $tocache);

// Turn any repeated white space into one space
$tocache = preg_replace('!\s+!', ' ', $tocache);

Now, I run that once per page change, then serve up the smaller HTML to users.

This is pretty much pointless though, as the process of gzipping makes the biggest difference. I do it because I might as well – I already am caching these files, so why not make myself feel clever first!

For CSS and JS I use SASS's compressed option, and uglifyJS to get those as one small file.

That means on a page I have 1 HTML file, 1 CSS and 1 JS, minimising the number of HTTP reqs and the amount of data to be transmitted.

Gzip + ensuring 1 css and 1 js is the biggest savings though.

Rich Bradshaw
  • 67,265
  • 44
  • 170
  • 236