5 ms·
About the twitter/facebook buttons. You can just delay until after the window.load event has occurred. It will have no impact on the page load, since the page i
by jreposa 14y ago
About the twitter/facebook buttons. You can just delay until after the window.load event has occurred. It will have no impact on the page load, since the page is fully rendered at that point.
$(window).load(function() { /* load twitter and Facebook buttons */ });
- niyazpk 14y agoWe do something like this: $(function(){ setTimeout(function(){ /* load twitter, facebook */ }, 2000); }); This tries to make sure that all the essential work to be done on the page is completed before the less important Twitter, FB buttons are loaded.
- bentlegen 14y agoThe onload event fires after the page has fully loaded - all scripts, image files, etc. I would say that it is more effective than your snippet for waiting until "essential work" has been finished.
- projct 14y agoYou are making part of your page always load at least 2 seconds slower than is probably necessary. $(function(){}); is shortcut for $(document).ready(); which waits until all other external content has been loaded. [1] If for some reason you are loading something else you need after .ready() fires, and you can't load that inside of a single .ready() call for some reason, you can potentially add multiple callbacks to .ready() (they will be executed in order [2]), or attach a .load() to that particular item instead (maybe even inside your .ready().) Timeout hacks are not a performance improvement. [1] http://api.jquery.com/ready/ http://api.jquery.com/ready/ [2] http://stackoverflow.com/questions/5263385/jquery-multiple-document-ready http://stackoverflow.com/questions/5263385/jquery-multiple-d...
- bentlegen 14y ago$(document).ready does "not wait until all other external content has been loaded". It fires when the DOM is fully parsed, irrespective of whether there are still images or iframes or other assets still loading. http://stackoverflow.com/questions/4395780/difference-bw-onload-and-document-readyfunction http://stackoverflow.com/questions/4395780/difference-bw-onl...
- j_s 14y agoI think he was getting at the idea that in general each page has some specific-to-the-page JavaScript work to do as soon as it's ready. The delay punts initialization of the less-important plugins, allowing time for the important stuff in a page-generic way. Your point that the delay is a messy way of accomplishing this is certainly valid.