维基百科 defines minification作为...
[...] the process of removing all unnecessary characters from source code without changing its functionality. These unnecessary characters usually include white space characters, new line characters, comments, and sometimes block delimiters, which are used to add readability to the code but are not required for it to execute.
我目前正在对我的 HTML、CSS 和 Javascript 执行此操作以节省带宽,但有人告诉我他记得浏览器在某些标签(即 ul
)之间没有空格时会出现错误行为和 li
元素)。这是真的吗?
在处理缩小代码时是否有任何值得注意的浏览器、代理或其他用户代理行为不当?
除了在查看源代码时失去可读性之外,缩小还有其他缺点吗?
最佳答案
someone told me that he remembers a browser misbehaving when there's no white space between certain tags (namely ul and li items). Is this true?
是的,在某些情况下,比如元素设置为显示 inline-block
或 inline
.
由于 <li>
之间的空白,以下两个列表将呈现不同元素:
html
<ul>
<li>simple</li>
<li>list</li>
</ul>
<ul><li>minified</li><li>list</li></ul>
CSS
li {
display: inline-block;
background: blue;
color: white;
}
渲染输出
关于javascript - 缩小 HTML、CSS 和 Javascript 是个坏主意吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23293168/