does Google analytics make a major effect on time to download a static web page?

后端 未结 15 1323
臣服心动
臣服心动 2021-01-07 22:44

I understand that by simply adding a script to the end of the body tag of a html document one makes it processable by Google analytics. My question is, is this likely to hav

相关标签:
15条回答
  • 2021-01-07 23:31

    Although downloading and running the actual ga.js is fast, what I've noticed all across Europe, on different connections/computers/OSes/browsers, is a MAJOR lag (anywhere from 0 to 30 (thirty) seconds) between the last byte of HTTP request and first byte of HTTP response.

    This is understandable, given the immense popularity of GA, but this is happenning before window.onload fires. So, if your page relies on JS and your users hit this lag, they are not going to analyze which component is responsible - they'll assume your site is horribly slow.

    A workaround for this is to register a window.onload function which will add the GA script. Example (using "window.onload=function()" for simplicity):

    window.onload = function() {
        var gaJsHost = (("https:" == document.location.protocol) 
                          ? "https://ssl." 
                          : "http://www.");
        var s = document.createElement('script');
        s.src = gaJsHost + "google-analytics.com/ga.js";
        s.type='text/javascript';
        var bodies = document.getElementsByTagName('body');
        if (bodies.length > 0) {
            bodies[0].appendChild(s);
        } else { // this should never happen, but sometimes does (curse you IE6!)
            document.appendChild(s);
        }
    
        // this says 100ms, but won't happen until ga.js is loaded
        window.setTimeout(function(){
            if (window['_gat']) {
                var pageTracker = _gat._getTracker("UA-xxxxxx-x");
                pageTracker._trackPageview();
            }
        },100);
    }
    
    0 讨论(0)
  • 2021-01-07 23:32

    Regarding server load, the scripts are pulled from Google's servers, not yours so there will be no noticeable server side impact. Obviously your pages will all be slightly larger than they were without the code to load the JavaScript, but you'll never notice the difference.

    0 讨论(0)
  • 2021-01-07 23:35

    If you add the code to the bottom of the page then it probably won't make much of a difference.

    If however, you want it to make no difference then I'd take a look at this link:

    http://lyncd.com/2009/03/better-google-analytics-javascript/

    It describes the approach that Steve Souders took to completely avoid any kind of I/O block.

    0 讨论(0)
  • 2021-01-07 23:36

    Yes it does have a performance hit see http://dotnetperls.com/Content/Google-Analytics-Speed.aspx . To speed up its recomended that you download the ga.js file locally and call that instead,Explained here http://www.askapache.com/javascript/google-analytics-speed-tips.html.

    0 讨论(0)
  • 2021-01-07 23:36

    Note too I've seen GA download a little GIF file with a hash attached to it... but I doubt the size of this will have much of an affect on performance.

    0 讨论(0)
  • 2021-01-07 23:39

    Yes.

    I feel browsing speed is much better since I added google analytics to addblock filter.

    0 讨论(0)
提交回复
热议问题