I'd prefer not to use the AddThis button because of some of their questionable business practices, however the AddToAny button performs rather poorly. The primary reason being inline JavaScript that blocks page loading/rendering. The good news is that there's opportunity for easy improvement. Currently the module adds inline JS during page load. This blocks the page load, and simply adds more things that need to happen before the page is done loading. But since only the button image is required for page rendering, the JavaScript can be lazy loaded after the page is finished rendering and in the background. Here's an example:

$(window).load(function(){
  var head = $("head").first() || document.documentElement;
  var script = document.createElement('script');
  script.type = 'text/javascript';
  script.async = true;
  script.src = 'some_script.js';
  head.insertBefore(script, head.lastChild);
});

This mimics the technique used by Google Analytics but more jQuery oriented. You can use the same technique to load CSS, iframes, or whatever else.

Comments

micropat’s picture

Status: Active » Closed (fixed)

Asynchronous loading is in 3.0!

xjm’s picture

Is the asynchronous loading enabled by default? Because I still often see my pages hang on a white screen with a "Waiting for static.addtoany.com..." status message.

micropat’s picture

Asynchronous loading is enabled by default.

What browser were you using? Perhaps a browser add-on was causing the hang because the script definitely shouldn't be blocking. This might be caused by a browser add-on, or perhaps a buggy/unstable browser. For instance, certain older versions of Firefox are known to always load scripts synchronously despite async methods.