Refreshing Social Media Widgets in AJAX Content

Many social media widgets are parsed upon page load, and thus adding new content via AJAX will not trigger the widgets to rebuild themselves.

Each widget has a different solution to force re-rendering.

I needed them for Twitter, Facebook, and GPlus. Add the following to your AJAX content (or fire it off yourself when you’ve done the AJAX call).

Twitter

$.ajax({ url: 'http://platform.twitter.com/widgets.js', dataType: 'script', cache:true});

Facebook

try { 
    FB.XFBML.parse(); 
} catch(ex) {};

Google Plus

try { 
	gapi.plusone.go();
} catch(ex) {};

Leave a Comment