admin管理员组文章数量:1336289
This may be a stupid question, but I still have it . Does having spaces between the code lines in anyway affect the performance of the JavaScript code.
How effective is the minified version of the JavaScript file? Any ways to optimize the code performance?
This may be a stupid question, but I still have it . Does having spaces between the code lines in anyway affect the performance of the JavaScript code.
How effective is the minified version of the JavaScript file? Any ways to optimize the code performance?
Share edited Aug 13, 2012 at 20:06 Rahul asked Aug 13, 2012 at 15:32 RahulRahul 1,5793 gold badges18 silver badges37 bronze badges 1- 2 Possible duplicate stackoverflow./questions/1181447/… – Adi Commented Aug 13, 2012 at 15:35
3 Answers
Reset to default 7Minifying code will decrease the time needed to download the file and initially parse and pile it. The runtime performance isn't going to be affected.
The effect is likely to be immeasurably small unless you have absolutely huge source files (tens of thousands of lines), in which case minifying it does make sense. How much effect minification has depends on how large the files are, but I've seen some libraries drop dramatically in size when minified (such as ExtJS).
Improving the runtime performance is something that can't really be covered in a single answer unless you've got specific code you want optimized. If you're looking to optimize the runtime performance of your code, start by profiling it and identifying where it is spending most of its time. If you're using Chrome, it has a built in profiler in its developer tools. Firefox may have one these days too, but I'm not sure.
It's not the performance that gets optimized by minified JS code but the script size. This improves your page's loading speed over slow connections.
The script code gets piled nowadays by the browser using so called JIT pilers. So the runtime is absolutely not affected by whitespace. If anything that there would be a tiny difference in the pilation time, but since the piler just skips whitespace i'd not even expect a measurable difference, not to mention a noticeable one.
If you want to really improve the runtime performance of your code than you won't get around hand optimizing your code yourself. There are millions of resources out there covering this topic.
Nevertheless optimizing for page load speed is a good thing since every millisecond counts to make your visitors happy ( http://www.strangeloopnetworks./web-performance-infographics/ ). And not everyone has a high speed internet connection. So when you are done with debugging your code minimizing it is not a bad idea especially for large code libraries like jquery or extjs.
As far as i know, spaces between the code lines doesn't affect performance, and the minified version of a JavaScript file is no more fast than the original.
The minified source code only downloads faster.
本文标签: Does having space between lines affect the performance of javascript codeStack Overflow
版权声明:本文标题:Does having space between lines affect the performance of javascript code - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742406401a2468909.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论