Guan’s blog

home

Loading Mint asynchronously

18 Mar 2011

I use Shaun Inman’s excellent Mint for analytics on this blog. The default instructions are to link to Mint’s JavaScript using a script element inside the head element. Unfortunately this means that page loading will block while Mint loads, which can add several hundred milliseconds to load time.

Fortunately Google provides some code to load Google Analytics asynchronously and this code can be easily adapted to Mint. Just put this at the bottom of your page and remove the script element for Mint from the top:

<script type="text/javascript">
(function () {
    var ma = document.createElement('script');
    ma.type = 'text/javascript';
    ma.src = '/mint/?js';
    ma.async = true;
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(ma, s);
})();
</script>