Performance of .get() vs multiple .load()s

220 Views Asked by At

thanks for looking,

I've got a situation where I want to .load() multiple divs from a static file. I recently found and read this SO question: jquery-multiple-load-in-a-div. The options were either

$('<div>').load('static.html #div1,#div2,...');

or

$.get('static.html',...,function(){ 
    $responseHTML.find('#div1').appendTo(...);
    $responseHTML.find('#div2').appendTo(...);
});

I'm pefectly happy to use either, but I wanted to know a bit more about the theory behind it. Am I right in thinking that '.load()' is probably doing the exact same thing as the '.get()' behind the scenes? Does that mean the .get() is faster?

Any other insights would be appreciated. CB.

1

There are 1 best solutions below

0
On

(Answering my own question after help from comments.)

If you check out the source http://james.padolsey.com/jquery/#v=git&fn=jQuery.fn.load and http://james.padolsey.com/jquery/#v=git&fn=jQuery.get ... both functions are just wrappers for an .ajax() call. The speed difference from wrapping is negligible, so I guess it's just personal coding style preference in this case.

Note, I also misunderstood originally that doing $.load('file #div1,#div2,..') is not the same as $.load('file #div1');$.load('file #div2');... so the OP title is misleading.

Thanks for everyone's help.