admin管理员组文章数量:1026985
I understand that minifying tries to reduce file size by removing whitespace characters. Sometimes things end up on one line, but more often than not, there are multiple lines. I noticed that line breaks happen wherever spaces occur. Wouldn't it be better just to have it all on one line?
I understand that minifying tries to reduce file size by removing whitespace characters. Sometimes things end up on one line, but more often than not, there are multiple lines. I noticed that line breaks happen wherever spaces occur. Wouldn't it be better just to have it all on one line?
Share Improve this question asked Jun 25, 2010 at 14:25 MatthewMatthew 15.7k28 gold badges92 silver badges124 bronze badges 1- possible duplicate of Why do we have newlines in minified JavaScript? – Matt Commented Feb 27, 2013 at 21:37
3 Answers
Reset to default 3Well with JavaScript, a line break can imply the end of a statement (in place of the ;
). So putting it all on one line could cause issues with the code functioning correctly.
I would guess that it depends on the minimizer you are using, but that could be one reason. I would think the minimizer would try and account for this and put in semicolons where it can, but this ability could vary wildly between them.
If you are using yuipressor-maven-plugin, you may face this issue. The YUI pressor plugin has an option linebreakpos for which the default value is zero. If you read the description about how this option is used by the original YUI pressor library at this page, you'll notice that a value of zero for this value means that a newline will be emitted after CSS rule or a semi-colon in javascript.
Fortunately, having a look at the implementation suggests an easy work-around. Just specify any value less than 0 and you should be good to go.
Given the lack of sample code and information about how the minification is being performed, my best guess would be: Whatever you are using to view the code is performing word wrapping and there aren't any real new lines in there.
I understand that minifying tries to reduce file size by removing whitespace characters. Sometimes things end up on one line, but more often than not, there are multiple lines. I noticed that line breaks happen wherever spaces occur. Wouldn't it be better just to have it all on one line?
I understand that minifying tries to reduce file size by removing whitespace characters. Sometimes things end up on one line, but more often than not, there are multiple lines. I noticed that line breaks happen wherever spaces occur. Wouldn't it be better just to have it all on one line?
Share Improve this question asked Jun 25, 2010 at 14:25 MatthewMatthew 15.7k28 gold badges92 silver badges124 bronze badges 1- possible duplicate of Why do we have newlines in minified JavaScript? – Matt Commented Feb 27, 2013 at 21:37
3 Answers
Reset to default 3Well with JavaScript, a line break can imply the end of a statement (in place of the ;
). So putting it all on one line could cause issues with the code functioning correctly.
I would guess that it depends on the minimizer you are using, but that could be one reason. I would think the minimizer would try and account for this and put in semicolons where it can, but this ability could vary wildly between them.
If you are using yuipressor-maven-plugin, you may face this issue. The YUI pressor plugin has an option linebreakpos for which the default value is zero. If you read the description about how this option is used by the original YUI pressor library at this page, you'll notice that a value of zero for this value means that a newline will be emitted after CSS rule or a semi-colon in javascript.
Fortunately, having a look at the implementation suggests an easy work-around. Just specify any value less than 0 and you should be good to go.
Given the lack of sample code and information about how the minification is being performed, my best guess would be: Whatever you are using to view the code is performing word wrapping and there aren't any real new lines in there.
本文标签: javascriptWhen I minify css or jswhy isn39t it all on one lineStack Overflow
版权声明:本文标题:javascript - When I minify css or js, why isn't it all on one line? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745638193a2160579.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论