Google shows a way to make smaller html files

2 views
Skip to first unread message

Evgeny

unread,
Jun 26, 2009, 3:19:42 AM6/26/09
to Haml
http://code.google.com/speed/articles/optimizing-html.html

Essentially, not all tags "require" a closing tag when using the HTML
dtd (not XHTML) - does HAML have a mode where he ignores these closing
tags, and thus makes the file size smaller?

Nathan Weizenbaum

unread,
Jun 26, 2009, 3:22:57 AM6/26/09
to ha...@googlegroups.com
Haml does indeed omit the closing tags of self-closing tags such as "br" and "meta" in HTML mode.

Evgeny

unread,
Jun 26, 2009, 3:34:17 AM6/26/09
to Haml
So can we expand that list to include the other tags mentioned in that
google article?
Some of them are not just "self-closing" tags like <br> and <meta>,
but rather tags with content - like <p> and <li>

Nathan Weizenbaum

unread,
Jun 27, 2009, 1:25:59 AM6/27/09
to ha...@googlegroups.com
No - I don't think Haml will ever do any optimizations that will actually change the rendering of a document. Consider for example

#foo
  %p bar
  baz

If we removed </p>, this would render as

<div id="foo">
  <p>bar
  baz
</div>

which is equivalent to

<div id="foo">
  <p>bar
  baz</p>
</div>

and not equivalent to

<div id="foo">
  <p>bar</p>
  baz
</div>

Unless you can come up with a way of removing the tags that is guaranteed never to produce this sort of change, it's not safe to include it.

Mislav Marohnić

unread,
Jun 27, 2009, 10:05:42 AM6/27/09
to ha...@googlegroups.com
Here's a proof of concept (monkeypatch):

Keep in mind this is still vulnerable to the issue Nathan explains:

On Sat, Jun 27, 2009 at 07:25, Nathan Weizenbaum <nex...@gmail.com> wrote:
Unless you can come up with a way of removing the tags that is guaranteed never to produce this sort of change, it's not safe to include it.

Nathan is right. You have to implement the logic on top of my monkeypatch to keep closing tags if the following content is inline tags or text nodes but should not be nested under the tag in question.
Reply all
Reply to author
Forward
0 new messages