SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,658
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)

    How does this code run?

    How does this code run? This is using jQuery to use JS to run CSS. For times when JS is off. Works perfect. It adds the class .js-on to the html if js in on. My question is this? I want to place all this code at the bottom of the page. I was surprised it works this way. Does the browser have to travel all the way back up to find the html tag (thus slowing it down?) or does it work different. I have 5 different ways to do this. I'm looking for the fastest. This way is clean because I already have jquery library on the page. Thanks.

    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript">
    $('html').addClass('js-on');
    </script>
    <style type="text/css">
    html.js-on #method1 {color:red;}
    </style>
    <p id="method1">Method #1</p>

    I'll just ask. What's the fasted out of these five methods if I need/want to place the needed code at the bottom of the page? Unfortunately I don't know enough about js to answer that myself. Reason being I have a large photo gallery that needs to load and I don't want any extra markup slowing it down. http://www.visibilityinherit.com/cod...javascript.php

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,718
    Mentioned
    103 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by EricWatson View Post
    Reason being I have a large photo gallery that needs to load and I don't want any extra markup slowing it down.
    I suggest then that you create a demo page for each of the six techniques, so that we can then help you come up with some timings for each of those techniques and also figure out certain pros and cons of each technique that you may want to stay aware of.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,658
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Well I set up some test pages. But each time I run them it is a different number. So that's no help it seems. You honestly don't know what the js engine does in that circumstance?

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,718
    Mentioned
    103 Post(s)
    Tagged
    4 Thread(s)
    Well I set up some test pages. But each time I run them it is a different number. So that's no help it seems.[/QUOTE]

    Most web browsers have a performance timeline where you can determine how long things take. There are also ways to have JavaScript record how long it takes so that you can perform multiple tests and then take an average.

    Where do you have those test pages?

    Quote Originally Posted by EricWatson View Post
    You honestly don't know what the js engine does in that circumstance?
    There is no single JS engine. We browsers all have their own different engines with different performance metrics, so the microseconds that one technique might have over another aren't as important as the time it takes for you to manage and maintain and understand whichever technique that you end up deciding to go with.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •