Quantcast
Channel: Crunchify
Viewing all articles
Browse latest Browse all 1037

How to Load Twitter Follow Button Script Asynchronously

$
0
0

Twitter Follow Button Optimization Asynchronous Loading How to Load Twitter Follow Button Script Asynchronously

I’m sure you must be using default Twitter Follow Button Script in your WordPress site/blog. Have you noticed some performance issue with that?

Well, The default Twitter Follow code, the script loads the like button synchronously. When you add the synchronous Twitter Follow button to your website, Page Speed Online will tell you to prefer asynchronous resources.

Google Page Speed Asynchronous Suggestion How to Load Twitter Follow Button Script Asynchronously Here is the Original Code:

<script>!function(d,s,id) {
	var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';
	if(!d.getElementById(id)) {
		js=d.createElement(s);
		js.id=id;
		js.src=p+'://platform.twitter.com/widgets.js';
		fjs.parentNode.insertBefore(js,fjs);
	}
}(document, 'script', 'twitter-wjs');</script>

Updated Code: (just add js.async=true;)

<script>!function(d,s,id) {
	var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';
	if(!d.getElementById(id)) {
		js=d.createElement(s);
		js.id=id;
		js.async=true;
		js.src=p+'://platform.twitter.com/widgets.js';
		fjs.parentNode.insertBefore(js,fjs);
	}
}(document, 'script', 'twitter-wjs');</script>

Another must read:

Here is a Large Button, with follower count example:

Here is a Small Button, without follower count example:

List of all WordPress Optimization Tips and Hacks.

The post How to Load Twitter Follow Button Script Asynchronously appeared first on Crunchify.


Viewing all articles
Browse latest Browse all 1037

Trending Articles