Reputation: 1579
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?
Upvotes: 2
Views: 2228
Reputation: 6256
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 compiled nowadays by the browser using so called JIT compilers. So the runtime is absolutely not affected by whitespace. If anything that there would be a tiny difference in the compilation time, but since the compiler 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.com/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.
Upvotes: 3
Reputation: 555
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.
Upvotes: 1
Reputation: 1604
Minifying code will decrease the time needed to download the file and initially parse and compile 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.
Upvotes: 7