Script Problems (Speed & Compatibility)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Adelson Anton

    Script Problems (Speed & Compatibility)

    Greetings fellow coders. Please check this page for a code which
    rearranges chess cells:


    There are 2 problems:
    1. It takes quite a bit for the function to run each time. I don't know
    how to speed it up further.
    2. The function runs twice on mozilla browsers for some reason.

    Any help is greatly appreciated. And hold your flames, this is my first
    usable JS script.
  • Adelson Anton

    #2
    Re: Script Problems (Speed & Compatibility)

    An idea just came to me. Maybe problem #2 is because after every time I
    click on the link, the onload event is fired. If I'm right, how do I
    avoid it?

    Comment

    • Mike

      #3
      Re: Script Problems (Speed & Compatibility)

      Not sure what you mean by slow. Seemed to work really fast with IE 6.0.

      Anyway in general string concatenation can be slow and before IE 6.0 setting
      the innerHTML property was pretty slow and I think is still slow for Mozilla
      compared to using the DOM methods. But I may be out of date with this.

      First I would recommend altering the code to use the DOM methods for element
      creatation rather than using innerHTML. But if you want to use innerHTML the
      faster way to perform string concatenation is to add the strings to an Array
      and then perform an Array.join();

      so

      [snip]

      var content = new String; // stores the table for output

      content = "<table border='0' width='432' height='432' cellspacing='0'
      cellpadding='0' >";
      // first border row
      content += "<tr height='9'>";

      [/snip]

      would become

      var content = new Array();

      content.push("< table border='0' width='432' height='432' cellspacing='0'
      cellpadding='0' >");
      // first border row
      content.push("< tr height='9'>");
      ..
      ..
      ..
      showContentObj. innerHTML=conte nt.join();



      "Adelson Anton" <adelson@mail.r u> wrote in message
      news:4093dbbe@d uster.adelaide. on.net...[color=blue]
      > Greetings fellow coders. Please check this page for a code which
      > rearranges chess cells:
      > http://s95005072.onlinehome.us/blog/Chess/chess.htm
      >
      > There are 2 problems:
      > 1. It takes quite a bit for the function to run each time. I don't know
      > how to speed it up further.
      > 2. The function runs twice on mozilla browsers for some reason.
      >
      > Any help is greatly appreciated. And hold your flames, this is my first
      > usable JS script.[/color]


      Comment

      Working...