#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    46
    Rep Power
    12

    Need to flush page output


    Hi all. I have some javascript tracking code at the bottom of my page (Google Analytics, along with several other tracking tools). For some reason, with Firefox 17.0.01, the entire page waits to display until all of the tracking pixels are fully loaded.

    What this means...is that if any of the tracking pixels load slowly, then the entire page takes forever to load.

    Does anyone know of a way to "flush" the page before the tracking pixels at the bottom, so that it loads quickly, while waiting on the pixels to finish loading?

    Thanks.
  2. #2
  3. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,158
    Rep Power
    183
    You could create the tracking code and/or image; after page load, but that may create a conflict with your tracking code statistics... if it relies on the document's onload event.

    Google Anylatics Documentation: https://developers.google.com/analyt...js/#quickstart
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    46
    Rep Power
    12
    Thanks web_loone. I'm really thinking more along the lines of PHP's flush() command. Is there something similar in HTML or javascript that can flush the output all the way up to the tracking code?
  6. #4
  7. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,158
    Rep Power
    183
    You could strip the html from in between the body tag and then once your tracking code is created and appended to the body tag; re-display your html back in between the body tag.

    Something along the lines of this:

    Code:
    var Html = [];
    
    function strip_html()
    {
    // flush and store content
    Html.push(document.getElementsByTagName("body")[0].innerHTML);
    document.getElementsByTagName("body")[0].innerHTML="";
    // create tracking code
    var tracking_script = document.createElement("script");
    tracking_script.setAttribute("type","text/javascript");
    tracking_script.setAttribute("src","tracker.js");
    document.getElementsByTagName("body")[0].appendChild(tracking_script);
    }
    function insert_html()
    {
    document.getElementsByTagName("body")[0].innerHTML = Html[0] += document.getElementsByTagName("body")[0].innerHTML;
    }
    function flush()
    {
     if (document.readyState=="interactive") {
      strip_html();
     }
     else if (document.readyState=="complete") {
      insert_html();
     }
    }
    document.onreadystatechange = function() {
     flush();
    }
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    46
    Rep Power
    12
    Thanks, I'll try that.

IMN logo majestic logo threadwatch logo seochat tools logo