Results 1 to 8 of 8
  1. #1
    Join Date
    Nov 2006
    Location
    Manchester
    Posts
    2,642

    Default Javascript question

    If a web page - not one of mine - had a line of code that called the file "google-analytics.com/ga.js" and repeated that line of code 200 times, would it run that file 200 times each time the page loaded or does it know to only run a script once no matter how often it is listed?
    Dennis, Francois, Melba and Smasher are competing to see who can wine and dine Lola Whitecastle and win the contract to write her memoirs. Can Dennis learn how to be charming? Can Francois concentrate on anything else when food is on the table? Will Smasher keep his temper under control?

    If only the 28th century didn't keep popping up to get in Dennis's way...

    #dammitbrent



    The eleventh annual Brenty Four serial is another Planet Skaro exclusive. A new episode each day until Christmas in the Brenty Four-um.

  2. #2
    Join Date
    May 2009
    Location
    Way under, down under.
    Posts
    4,067

    Default

    Does sound messy - I think generally with such a declaration it doesn't run the file 200 times, but there's no need for it and it's messy.

    Usually with such a call, it's setting up a reference library, which isn't used until a related function is called.

    Hope that helps - I'm not an expert in JS, but in comparable languages, it'd help to see the full line to know what it's doing with the line, I'm assuming it's a kind of library call. If it's however an OPEN FILE type call - yes indeed it would open it 200 times.

    Still sounds very messy though.
    Remember, just because Davros is dead doesn't mean the Dalek menace has been contained ......

  3. #3
    Join Date
    May 2009
    Location
    Way under, down under.
    Posts
    4,067

    Default

    I know I'm saying messy a lot - I need coffee!
    Remember, just because Davros is dead doesn't mean the Dalek menace has been contained ......

  4. #4
    Join Date
    Nov 2006
    Location
    Manchester
    Posts
    2,642

    Default

    The full section of code is -

    <!--Google analytics tag-->

    <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 src="http://www.google-analytics.com/ga.js" type=text/javascript></SCRIPT>

    <SCRIPT type=text/javascript>
    try {
    var pageTracker = _gat._getTracker("**********");
    pageTracker._setDomainName("none");
    pageTracker._setAllowLinker(true);
    pageTracker._trackPageview();
    } catch(err) {}
    </SCRIPT>
    <!--Google analytics tag-->

    </body>

    The part in bold appears 199 times before the code continues.
    Dennis, Francois, Melba and Smasher are competing to see who can wine and dine Lola Whitecastle and win the contract to write her memoirs. Can Dennis learn how to be charming? Can Francois concentrate on anything else when food is on the table? Will Smasher keep his temper under control?

    If only the 28th century didn't keep popping up to get in Dennis's way...

    #dammitbrent



    The eleventh annual Brenty Four serial is another Planet Skaro exclusive. A new episode each day until Christmas in the Brenty Four-um.

  5. #5
    Join Date
    May 2009
    Location
    Way under, down under.
    Posts
    4,067

    Default

    http://www.jsworkshop.com/articles/02scriptsrc.html

    http://www.quirksmode.org/js/placejs.html

    Right, reading through the lines, it says for each use of <SCRIPT> it will place all the code within the script. So all those itterations will possibly cause multiple downloads of that file at script run time, making the webpage larger in memory and slower than required.

    As stated I believe it would be better to drop to 1 use of that script call.
    Remember, just because Davros is dead doesn't mean the Dalek menace has been contained ......

  6. #6
    Join Date
    Nov 2006
    Location
    Manchester
    Posts
    2,642

    Default

    That's what I thought - it's on every page of our company intranet and it's running like a bollard. I needed confirmation before telling them they need to remove it. Javascript doesn't work well in our CITRIX environment anyway and adding a load of superfluous code isn't the answer.

    Thanks hugely - I've had a quicker response from New Zealand than I got from upstairs. That's 2009 for you.
    Dennis, Francois, Melba and Smasher are competing to see who can wine and dine Lola Whitecastle and win the contract to write her memoirs. Can Dennis learn how to be charming? Can Francois concentrate on anything else when food is on the table? Will Smasher keep his temper under control?

    If only the 28th century didn't keep popping up to get in Dennis's way...

    #dammitbrent



    The eleventh annual Brenty Four serial is another Planet Skaro exclusive. A new episode each day until Christmas in the Brenty Four-um.

  7. #7
    Join Date
    May 2009
    Location
    Way under, down under.
    Posts
    4,067

    Default

    Like I say I'm making a guestimate on that, but no-way is this a sensible thing.

    Mind you ever turned and MS Office into a HTML page - it's full of junk!
    Remember, just because Davros is dead doesn't mean the Dalek menace has been contained ......

  8. #8
    Join Date
    Dec 2006
    Location
    Oxford, UK
    Posts
    635

    Default

    Quote Originally Posted by WhiteCrowNZ View Post
    Mind you ever turned and MS Office into a HTML page - it's full of junk!
    Did that the first time I tried writing documents as HTML pages by just resaving them as Word files... wound up spending hours tearing out all the unnecessary formatting code to the point where I found it was easier to redo them all them from scratch as very basic HTML!
    We ride tornadoes. We eat tomatoes.

Similar Threads

  1. A Blu Ray question
    By Anthony Williams in forum DVD and Blu-ray
    Replies: 6
    Last Post: 30th Apr 2012, 10:58 AM
  2. Wii Question
    By Rob McCow in forum Mr Smith, I Need You!
    Replies: 7
    Last Post: 26th Dec 2009, 8:13 PM
  3. Astronomy question
    By Jamie McCrimmon in forum General Forum
    Replies: 6
    Last Post: 8th Dec 2008, 4:23 PM