Optimized order of HTML attributes for compression

家住魔仙堡 提交于 2019-12-04 02:01:55

Your aim would be to encourage repeated content. So <p class="foo" id="a">bar</p>...<p class="foo" id="b">bof</p> might indeed be easier to compress than <p id="a" class="foo">bar</p>...<p id="b" class="foo">bof</p>, and both would typically compress easier than <p class="foo" id="a">bar</p>...<p id="b" class="foo">bof</p>.

But really, the difference is going to be minuscule. You'd be much better off just writing your markup in the most readable fashion for your own benefit and letting mod_deflate get on with its job. You're going to have to go a long way to save even a single TCP packet with this kind of micro-optimisation, and second-guessing the compressor at a micro level can often generate unexpected, possibly negative results.

For some elements readability might well also mean putting the ‘common’ attributes first, eg <input type> is usually the first listed attribute; typically you'll work out your own attribute order style and if it's consistent I suppose that'll save you a few bytes here and there. I wouldn't choose raw alphabetical as the consistent order. All that has going for it is that it's what Canonical XML will produce.

Even google.com's front page, infamous for its dedication to shaving off bytes at the expense of readability, basic validation and every kind of good practice, doesn't bother use one consistent order for attributes.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!