Google Plus One async code Minified

2 Août

Google just released his new async snippet to boost the loading of their « +1 » button.Google Plus One Minified

As the Google Analytics snippet, it could be improved and save you a few bytes !

Lets’s minify it !

This snippet is based on the HTML5 Boilerplate’s Google Analytics snippet.

Simply replace this code (original from Google) :

  (function() {
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = 'https://apis.google.com/js/plusone.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  })();

With this one :

(function(d,t){var p=d.createElement(t),s=d.getElementsByTagName(t)[0];p.async=1;
p.src='https://apis.google.com/js/plusone.js';
s.parentNode.insertBefore(p,s)}(document,'script'));

If you need a translation (go here to see the country codes), simply add this line before the code :

window.___gcfg = {lang: 'THE-LANG'};

Now, this code is as small as it can !

Please spread this tip if you find it interesting and don’t forget to link back to here 😉

Update : According to a trusted source ( http://mathiasbynens.be/notes/async-analytics-snippet#async ), it is now not necessary to keep async=1 in the snipped, to there is 10 more bytes saved !

(function(d,t){var p=d.createElement(t),s=d.getElementsByTagName(t)[0];
p.src='https://apis.google.com/js/plusone.js';
s.parentNode.insertBefore(p,s)}(document,'script'));
Publicités

2 Réponses to “Google Plus One async code Minified”

  1. Fask octobre 2, 2011 à 8:24 #

    thanks, it works very well

Trackbacks/Pingbacks

  1. Google Plus One ‘async’ Code Minified | Rapid Purple - août 2, 2011

    […] button snippet. Thomas over at Web2.0Hub has taken the new ‘async’ snippet and minified it to make it even smaller. Not sure what that means? Essentially minification is the practice of […]

Laisser un commentaire

Entrez vos coordonnées ci-dessous ou cliquez sur une icône pour vous connecter:

Logo WordPress.com

Vous commentez à l'aide de votre compte WordPress.com. Déconnexion / Changer )

Image Twitter

Vous commentez à l'aide de votre compte Twitter. Déconnexion / Changer )

Photo Facebook

Vous commentez à l'aide de votre compte Facebook. Déconnexion / Changer )

Photo Google+

Vous commentez à l'aide de votre compte Google+. Déconnexion / Changer )

Connexion à %s

%d blogueurs aiment cette page :