开发者

how to increase Speed of a component made from Javascript or JQuery?

开发者_JS百科

I want to make my component faster, I am using Javascript and JQuery to build that. I am using JSON object to communicate with component and back-end is python. Is there any suggestion to make component faster?


Setup some analysis to see what takes time to process. Then decide if you want to try to optimize the javascript and client code, the communication up/down with the server or the actual speed of the python execution. When you have decided what you want to make faster, you can post samples of that to this site and people will probably be willing to help you.


On the client side, you can benchmark your script(s) using getTime()

var start = (new Date).getTime();
 /* Run your script. */
var diff = (new Date).getTime() - start;
alert(diff)

And see what is taking long in a script exactly. But its hard do tell what could be optimized if you don't post any code.


If speed is the issue, and you by profiling discover that js is the culprit, then I would look into replacing the jQuery with vanilla javascript, or a more optimized library.

As jQuery tries to do 'everything' and trains its users into wrapping everything in $(), its bound to introduce unnecessary method calls (I've seen that a single call to $() can result in upto 100+ method calls).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜