最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Does having space between lines affect the performance of javascript code - Stack Overflow

programmeradmin1浏览0评论

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
Add a ment  | 

3 Answers 3

Reset to default 7

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

发布评论

评论列表(0)

  1. 暂无评论