开发者

Is it a fact that a smaller jQuery plugin (in KB) will perform better than same plugin with the same functionality but of a bigger size?

开发者 https://www.devze.com 2022-12-15 13:30 出处:网络
Or does it depend on the way in which it is written? My question is related to page rendering time. Ca开发者_如何学Cn we determine which will give better performance?

Or does it depend on the way in which it is written?

My question is related to page rendering time. Ca开发者_如何学Cn we determine which will give better performance?

Should we always choose a smaller sized plugin?


If you mean that you have two plugins with comparable functionality, but different size (not just minified but really different code), the answer is: maybe. One thing is obviously for sure: the smaller plugin will load faster. But for a million reasons, the bigger plugin can be faster after that. Without benchmarks, you can only guess.


Only way to know is to measure it with tool like yslow or google page speed

e.g. I can write a simplest plugin which can halt your page rendering, or downloads too many things.

But usually if both are jquery plugin with exact same behaviour, shorter the better, but if you are comparing two different things e.g. one jquery plugin , one plain javascript then you must also consider the size of jquery library and such things.


A normally minified JavaScript file with whitespace removed will run equally fast as non minified. The difference is neglible, as the only benefit for the interpreter is that it doesn't have to skip as much whitespace. The benefit of minified JS files comes from reduced file sizes, not from increased performance.

But if a JavaScript is file 'packed' with Dean Edward's Packer, that's a whole different case as it might actually decrease performance because the code must be evaluated first with eval(). That's why in some cases it might not be advisable to pack with the 'maximum' setting – that is, with the 'Base62 encode' option.

So, if you're looking for performance optimizations, don't start by stripping whitespace or shortening variable names :)

But as an answer to your last question, yes, you should always choose the minified version. At least it will load faster due to it's smaller filesize.


Assuming you mean that the one plugin file has been minified, I would say in the majority of cases, yes.

But it really depends on hundreds of factors...


jquery distributes a "minified" version of the library. the code is stripped of inessential whitespace and other elements using a tool called JSMin. it's identical in function to the non-minified version, but loads much quicker. if you are debugging tho, you might find it easier to use the full version.

0

精彩评论

暂无评论...
验证码 换一张
取 消