optimization - Minimize html, doubts and questions -
minimizing html section on google's page speed there still room improvement.
my site dynamic , html deflated
there no reason put more pressure on server (i don't want minimize pages real time before sending).
what minimize template files. templates files mix of php
, html
i've come code think pretty safe community revised.
// loop trough template files // php cleaned first line-comments not interfere regex $original = file_get_contents($dir.'/'.$file); $php_clean = php_strip_whitespace($dir.'/'.$file); $minimized = preg_replace('/\s+/', ' ', $php_clean);
this make template files single long file alternated places db content inserted. google's homepage source looks more or less wonder if follow similar approach.
question 1: antecipate potencial problems?
question 2: there anyway better (more efficient this)?
and please remember i'm not trying validate html templates not valid html (header , footer includes, example).
edit: take consideration template files minimized on deploy. css , javascript files minimized , compressed using yui compressure , closure, template files minimized like-wise, on deploy. not on client-request.
thank you.
google's own closure templates (soy) strips whitespace @ end of line default, , template designer explicitly inserts space using {sp}
. isn't enough reason switch away php, wanted bring attention.
in addition, realize html 4 allows exclude tags, recommended page speed documentation on minifying html (http://code.google.com/p/page-speed/wiki/minifyhtml). can exclude </p>
, </td>
, </tr>
, etc. complete list of elements can omit end tag, search "- o
" in html 4 dtd (http://www.w3.org/tr/rec-html40/sgml/dtd.html). can omit <html>
, <head>
, <body>
, , <tbody>
tags entirely, both start , end tags optional ("o o
" in dtd).
you can omit quotes around attributes (http://www.w3.org/tr/rec-html40/intro/sgmltut.html#h-3.2.2) such id
, class
(with single class name), , type
have simple content (i.e., matches /^[-a-za-z0-9._:]+$/
). attributes have single possible value, can exclude value (e.g., checked
rather checked=checked
).
some people may find these tips repulsive because we've been conditioned many years prepare upcoming world of simple lalr parsers xhtml. thus, tools dave raggett's html tidy generate html proper closing tags , quotes around attribute values. let's face it, browsers have parsers understand html 4, new browser use html 5 parser rather xhtml, , should comfortable writing html optimized size.
that being said, besides couple large companies google , facebook, guess page size negligible component of latency, if you're optimizing own site it's because of own obsessive tendencies rather performance.
Comments
Post a Comment