I have simple question if worths to “cache” DOM changes even outside if the loop (for cycle,..) In case I have e.g. 1000 upcoming changes it makes huge performance boost (as I have heard, not measured myself), but what if I only replacing content like this?
jQuery("#subMenu").html( jQuery( html ).find( "#subMenu" ).html() );
jQuery("#pageMain").html( jQuery( html ).find( "#pageMain" ).html());
jQuery("#text").html( jQuery( html ).find( "#text" ).html());
I can do this
var cachedDOM = jQuery("body").html(); //edited
jQuery(cachedDOM).find("#pageMain").html( jQuery( html ).find( "#pageMain" ).html());
jQuery("body").html(cachedDOM);
It would be propably faster, but I need than rebind all of my events, and so on..
Is it really better approach to cache DOM in this case? I dont think so, but I’d like to make the page as quick as possible(especially in older IEs)
Thanks
Always use JQuery’s built-in selectors vs trying to ‘cache’ and traverse a variable. It’s counter-intuitive to start your traversal from the body anyway.
Proof the selectors are ridiculously faster than pseudo-caching: http://jsperf.com/pseudo-dom-cache