对于COM pression HTML的优化顺序属性 [英] Optimized order of HTML attributes for compression

查看:118
本文介绍了对于COM pression HTML的优化顺序属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读的地方,举办HTML按照一定的顺序,可提高玉米pression为HTML文档的速度的属性。 (我想我读这从谷​​歌或雅虎推荐更快的网站)。如果我没有记错,该建议是把最常用的属性第一个(如 ID 等),然后把剩下的字母顺序排列。

I read somewhere that organizing HTML attributes in a certain order can improve the rate of compression for the HTML document. (I think I read this from Google or Yahoo recommendation for faster sites). If I recall correctly, the recommendation was to put the most common attributes first (e.g. id, etc.) then put the rest in alphabetical order.

我有点被这个迷惑。例如,如果每一个 P 标记后 ID 属性被摆正,在 ID 将包含唯一的值。因此,重复的字符串将被限制在此:&LT,P ID =(比如有&LT,P ID =1> &LT,P ID =2/> )因为 id的值必须是唯一的,我认为这实际上造成了不利的影响到COM pression。

I'm a bit confused by this. For example, if id attributes were put right after every p tag, the id would contain unique values. Thus, the duplicated string would be limited to this: <p id=" (say there were <p id="1"> and <p id="2"/>). Because the value of id needs to be unique, I see this as actually causing an adverse effect to the compression.

难道我错了吗?

如果我需要去通过与随机排序属性的静态页面,我应该用什么逻辑来组织的属性,以达到最大的COM pression?

If I needed to go through a static web page with randomly ordered attributes, what logic should I use to organize attributes to achieve maximum compression?

请注意:我说的是GZIP COM pression(如果该事项): http://www.gzip.org /algorithm.txt

NOTE: I'm talking GZIP compression (if that matters): http://www.gzip.org/algorithm.txt

推荐答案

你的目标是鼓励重复的内容。因此,&其中,P类=富ID =A&GT;巴≤; / P&GT; ...&其中,P类=富ID =B&GT;转炉&LT; / P&GT; ,甚至可能会更容易COM preSS比&LT,P ID =A级=富&GT;巴≤; / P&GT; ...&LT; p ID =B级=富&GT;转炉&LT; / P&GT; ,并且两个很典型的COM preSS比&LT容易,P类=富 ID =A&GT;巴≤; / P&GT; ...&LT,P ID =B级=富&GT;转炉&LT; / P&GT;

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>.

但实际上,差异将是微不足道的。你会好得多只是写您的标记在最可读的方式为自己的利益,让mod_deflate模块获得与它的工作。你将不得不走很长的路,甚至保存这种微型优化一个TCP数据包,第二猜测的COM pressor在微观层面上往往能产生意想不到的,可能是负的成绩。

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.

对于某些元素,可读性很可能也意味着将首先共同的属性,例如:&LT;输入类型&GT; 通常是第一家上市的属性;通常你会制定出自己的属性以便风格,如果是一致的,我想那会在这里和那里为您节省几个字节。我不会选择生按字母顺序排列的一致的顺序。所有这些都为它去就是它就是规范的XML将产生。

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.

甚至google.com的头版,臭名昭著的奉献精神,以削去字节可读性,基本验证和各种良好做法的代价,不打扰使用一个一致的顺序属性。

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.

这篇关于对于COM pression HTML的优化顺序属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆