0

I am trying to increase the speed on IE for the following javascript code on my page:

http://www.ufs.unsw.edu.au/gpa

I have created another version of this by searching on internet about some tips to increase the speed of Javascript

http://www.ufs.unsw.edu.au/gpa-fast

Instead of storing values in a string, I have used an array in to store values in a loop and used array.join to show those values on page.

function ajaxQuery($obj)
  {
      var domObj=[], i=0;
      var startEXP="<div class='notesclick'><div><img src='img/notes.png' width='25' height='25' alt='notes'></div><div class='notes'><ul>";
     var endEXP="</ul></div></div>";
      $obj.find('Course').each(function(){

          var course=$(this);
                    var Code = course.attr("ACAD");
                    var Bof = course.attr("Name");
                    var Yrs = course.attr("Duration");
                    var S2= course.attr("S2Entry");
                    var Stream = course.attr("FSstream"); 
                    var GPA = course.attr("GPA"); 
                    var English = course.attr("EngGrade");                      var addNotes=startEXP;

                    //find notes
                    $(this).find('Note').each(function(){

                        var Notes=$(this).attr("Text");

                        addNotes=addNotes+"<li>"+Notes+"</li>";


                        });
                addNotes=addNotes+endEXP;

                if(addNotes==startEXP+endEXP)
                {
                    addNotes="&nbsp;";
                }

                if(S2=="Y")
                {
                S2="<span class='red'>+</span>";    
                }else
                {
                    S2="";
                }

    domObj[i]='<tr><td>'+Code+' '+S2+'</td><td>'+Bof+'</td><td>'+Yrs+'</td><td>'+Stream+'</td><td>'+GPA+'</td><td>'+English+'</td><td>'+addNotes+'</td></tr>';          

    i++;

    /*$('#gpa tbody').append('<tr><td>'+Code+' '+S2+'</td><td>'+Bof+'</td><td>'+Yrs+'</td><td>'+Stream+'</td><td>'+GPA+'</td><td>'+English+'</td><td>'+addNotes+'</td></tr>');  */

  }); //end course

  $('table#gpa tbody').append(domObj.join(""));

     }

and above function is being called from function init() which is given below:

function init($xml, Yeari, Facultyi, oTable)
        {
            var Year=Yeari, Faculty=Facultyi, tabArr=[], i=0;

            //init table            

            //console.log("Table is "+oTable);
            //alert(Faculty+" "+Year);


            if(Faculty=="all")
            {
                oTable.fnClearTable(); //clear previous table
                //console.log("all");
            $('#gpa tbody').empty();    
            $xml.find("Year[Year='"+Year+"']").find('Faculty').each(function(){
                ////console.log("Faculty "+$(this).attr("Name"));
                ajaxQuery($(this)); 


 }); //end faculty

And below is the main function from where init() is being called:

$(document).ready(function(){        




     $.ajax({
            type: "GET",
            url: "../loader/UNSW_UGRAD_COURSE_DATA.xml",
            dataType: "xml",
            success: function(xml) {
                ////console.log("Reading Success");
                var oTable=$('#gpa').dataTable( {
    "aLengthMenu": [[10, 30, 50, 100, -1], [10, 30, 50, 100, "All"]],
    "iDisplayLength" : -1,
    "oLanguage": {
"sSearch": "Search by keyword" 
}
  });
                init( $(xml), 2014, "all", oTable);
                streamChanger();

                $('#year_btn').on("change", function(){
                setYears($(xml), oTable);   
                streamChanger();                
                }); 

            $('#faculty_btn').on("change", function(){
                setOptions($(xml), oTable);     
                                                                           streamChanger();                             

                   });                  
                },
                error:function(){
                alert("Reading failed");
  }

     }); //end ajax function    


    }); /* end ready */

But when I load it in IE, it still takes almost the same amount of time as gpa page. Can somebody advise me how I can improve the speed of this page please?

4

0 回答 0