Follow me: @D_mitar

Most read posts recently



Sep 15th 2008 × Google analytics script via domready and mootools

Hate it when your site display is being slow while it waits for google analytics?

Google Analytics is just great. But, regretfully–it often causes a delay in my sites’ display. Loading the remote script can pause the domready (as the browser waits to see if the script it is evaluating won’t affect the DOM in some way). The result: often page load times increase by a few seconds.

But there is a simple fix. Here is sample the code provided by google to include into your page:

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-1199722-1");
pageTracker._trackPageview();
</script>

The solution for a nice fast page load: go to domready!

Simply rewrite this as a part of your normal domready function:

// google analytics via mootools / domready.
window.addEvent("domready", function() {

    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    new Asset.javascript(gaJsHost + "google-analytics.com/ga.js", {
        onload: function() {
            var pageTracker = _gat._getTracker("UA-1199722-1"); // your id here
            pageTracker._initData();
            pageTracker._trackPageview();
        }
    });
}); // end domready

Google won’t ever interfere with your page load again!

no

Sep 15th 2008 × thawte site seal via domready

unfortunately, we have no Thawte certificate ourselves so this demo will show the badge as ‘invalid certificate’.


The problem with the Thawte Site Seals…

After having developed a site for a client, we were asked to include the THAWTE site seals that verify the site’s authenticity. That is all fine, but the seal uses

<script src="https://siteseal.thawte.com/cgi/server/thawte_seal_generator.exe"></script>

tags and holds the DOM load, often causing a performance drop — especially so if Thawte’s server is running slow and your page waits on the DOMREADY event….

The solution for a nice clean seal: Get rid of the sealgenerator.exe

Remove the code supplied by thawte code and replace with this goodness:

window.addEvent("domready", function() {
    // written for mootools 1.2
    var doSeal = function(targetObject) {
        // show thawte seal code w/o the reference to their exe in a dom compliant way
        var loc     = window.location.href;
        var sealLoc = "https://www.thawte.com/core/process?process=public-site-seal-cert-details&public-site-seal-cert-details.referer=" + loc;
        new Asset.image("https://siteseal.thawte.com/site-seal/image?g5ff7fe3df88d8fafaa6035dc97152679ga45f4b102502fefbd20332591412323c" + (new Date()).getTimezoneOffset() + "g5d43a4e836d7d07a50759fb1da9cc900g1a0452b749ddb29083736b34ef4a14e9ga45f4b102502fefbd20332591412323c" + loc, {id: 'sealimage'})
            .inject(targetObject).addClass("cur").set("title", "click to verify").addEvent("click", function() {
                window.open(sealLoc,'ga3ef4eb41dcac740b918440eb9cd19c8','height=500,width=516,scrollbars=yes,status=1');
            });
    } // end doSeal

    // embed it...
    doSeal($("seal"));
});// domready