user2367386
user2367386

Reputation:

Addthis javascript asynchronous tweaking

On my page here I'm adding asynchronous loading to the addthis javascript, but I'm still learning js so I'm not sure where to place it.

The code I have is:

<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_default_style ">
<a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
<a class="addthis_button_tweet"></a>
<a class="addthis_button_pinterest_pinit" pi:pinit:layout="horizontal"></a>
<a class="addthis_counter addthis_pill_style"></a>
</div>
<script type="text/javascript">var addthis_config = {"data_track_addressbar":true};</script>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=xxxxx"></script>
<!-- AddThis Button END -->

Here are the directions:

To enable asynchronous loading, add the querystring parameter "async" to the end of the addthis_widget.js script tag. Here's an example:

<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#async=1"></script> 

This will prevent all AddThis assets from loading except for the initial script. When you're ready for AddThis to load, call the function "addthis.init()", like this:

       function initAddThis() 
 {
      addthis.init()
 }
 // After the DOM has loaded...
 initAddThis();

My questions are, how do I place #async=1 in place of my username and do I add the init just after?

There's also a big gap coming from the iframce next to twitter I don't know how to reduce.

Worst of all, the URL posted on the social networks e.g. facebook go to a blank page and have the following URL: http://www.inside-guides.co.uk/brentwood/children-and-parenting/activity-and-play-centres/timbuk2-kids-activity-centre-383.html?fb_action_ids=10151964783697905&fb_action_types=og.likes&fb_ref=.Ul0sB9xtelP.like&fb_source=other_multiline&action_object_map=%7B%2210151964783697905%22%3A128186320684674%7D&action_type_map=%7B%2210151964783697905%22%3A%22og.likes%22%7D&action_ref_map=%7B%2210151964783697905%22%3A%22.Ul0sB9xtelP.like%22%7D

Any ideas much appreciated

Upvotes: 2

Views: 3422

Answers (1)

Paul
Paul

Reputation: 354

Your first question - how you add #async=1 - is easy: Just put it in the addthis_config variable. Here's example code:

<script type="text/javascript">
var addthis_config = {
    "data_track_addressbar":true, 
    "pubid": 'xxxxx'
};
</script>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#async=1"></script>

For your second question - how you add the init call just after - just put it after the code in your code editor.

Finally, the reason that posts to Facebook are failing is that your web app isn't set up properly to handle query parameters. For example, this URL - http://www.inside-guides.co.uk/brentwood/children-and-parenting/activity-and-play-centres/timbuk2-kids-activity-centre-383.html?foo=bar - also fails. If you put anything after a ? in the URL it won't load. Your developer will have to fix this.

Upvotes: 2

Related Questions