缩小HTML,CSS和Javascript是个坏主意吗? [英] Is minifying your HTML, CSS, and Javascript a bad idea?
问题描述
Wikipedia 将缩小定义为...
Wikipedia defines minification as...
[...]从源代码中删除所有不必要的字符而不更改其功能的过程.这些不必要的字符通常包括空格字符,换行符,注释,有时还包括块定界符,这些字符用于增加代码的可读性,但并非强制执行.
[...] 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
项目)之间没有空格时,他记得浏览器的行为异常).这是真的吗?
I'm currently doing this to my HTML, CSS and Javascript in order to save bandwidth, but 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?
在处理缩小代码时,是否存在任何行为不当的著名浏览器,代理或其他用户代理?
除了在查看源代码时会失去可读性之外,还有其他缺点要缩小吗?
推荐答案
某人告诉我,他记得有一个浏览器出现异常时, 某些标签(即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
.
Yes, in certain circumstances, like if the elements are set to display inline-block
or inline
.
由于<li>
元素之间的空格,以下两个列表将呈现不同的外观:
The following two lists will render differently, because of the whitespace between the <li>
elements:
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;
}
渲染输出
这篇关于缩小HTML,CSS和Javascript是个坏主意吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!