Tag Archives: optimization

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;

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];