jQuery 'deferred object/promises' Performance?
Does any one know of any significant performance penalties involved with using the new jQuery 'promises/deferred object' pattern over the old jQ开发者_运维知识库uery style ajax methods that had standard 'success' and 'error' callbacks?
I know that moving forward we don't have much option now because 'deferred' objects are built into the AJAX core now but just wondered if there was any measurable difference and if the new 'promises' design pattern was actually more efficient than just old school anonymous function callbacks?
Kind regards, Mark
There should be no difference. It's just syntactic sugar.
If you care about performance don't use the jQuery abstraction.
Create your own XMLHttpRequest
object and handle it in pure JS.
[Edit]
To rephrase: There is a very minor performance penalty for the new deferred/promises wrapper because it has a couple more layers and functions to go through.
The performance difference is probably an order of magnitude lower then the performance difference for using jQuery for ajax instead of XMLHttpRequests.
Both of these differences are pretty neglible compared to the flexibility and cross browser compliance they offer you.
If they matter then put blunty your having far too many ajax requests going off.
精彩评论