开发者

How is jQuery so fast?

开发者 https://www.devze.com 2023-02-02 13:23 出处:网络
开发者_Go百科I have a rather large application which, on the admin frontend, takes a few seconds to load a page because of all the pageviews that it has to load into objects before displaying anything

开发者_Go百科I have a rather large application which, on the admin frontend, takes a few seconds to load a page because of all the pageviews that it has to load into objects before displaying anything. Its a bit complex to explain how the system works, but a few of my other questions explains the system in great detail. The main difference between what they say and the current system is that the customer frontend no longer loads all the pageviews into objects when a customer first views the page - it simply adds the pageview to the database and creates an object in an unsynchronised list... to put it simply, when a customer views a page it no longer loads all the pageviews into objects; but the admin frontend still does.

I have been working on some admin tools on the customer frontend recently, so if an administrator clicks the description of an item in the catalogue then the right hand column will display statistics and available actions for the selected item. To do this the page which gets loaded (through $('action-container').load(bla bla bla);) into the right hand column has to loop through ALL the pageviews - this ultimately means that ALL the pageviews are loaded into objects if they haven't been already. For some reason this loads really REALLY fast. The difference in speed is only like a second on my dev site, but the live site has thousands of pageviews so the difference is quite big...

So my question is: why is it that the admin frontend loads so slowly while using $(bla).load(bla); is so fast? I mean whatever method jQuery uses, can't browsers use this method too and load pages super-fast? Obviously not as someone would've done that by now - but I am interested to know just why the difference is so big... is it just my system or is there a major difference in speed between the browser getting a page and jQuery getting a page? Do other people experience the same kind of differences?


I mean whatever method jQuery uses, can't browsers use this method too and load pages super-fast?

jQuery only has available to it that which the browser provides (the DOM API). Nothing more. jQuery brings nothing extra to the table, and performs no magic tricks.

It is basically just a layer over that API, as such, it is actually slower than if you just used the API directly.

...this has received so many up votes suggests that other people experience the same speed increase when using jQuery.

You received upvotes because you praised jQuery for being fast. I think this is evidenced by the fact that none of these upvoters bothered to point out that jQuery can not somehow be faster than the browser.

If you had criticized jQuery, I'm guessing you would have been downvoted by some users.


Facebook has done a lot of research into this area (loading pages in parts by Javascript rather than all at once).

See their "BigPipe" technology explained here: http://www.facebook.com/notes/facebook-engineering/bigpipe-pipelining-web-pages-for-high-performance/389414033919


Without seeing some code, its hard to speculate but I suspect if you were to run your tests in Firefox/Firebug or IE/Fiddler, you would see many http connections being opened when you browse to each "part-page" directly. When you load each "part-page" using jQuery, you're only loading the "part-page" content and not any CSS, JS or image files.

0

精彩评论

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