title: Javascript scripts slows down to nothing
body: <p>I have made a js script to convert images (300+ in number) to base-64.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
          var onderdelen, afbeeldingen;
          var c=document.getElementById("myCanvas");
          var container = $("#container ul");
          var lengte = container.length;
          var speed = 1000;
          dataStart = "{\"onderdelen\":[";
          dataEnd = "]}";
  
          convertToBase64 = function(convertImg){
              if(null == convertImg){
                  return "";
              }else{              
                  c.width = convertImg.width;
                  c.height = convertImg.height;
  
                  ctx=c.getContext("2d");         
                  ctx.drawImage(convertImg,0,0);
                  dataURL = c.toDataURL("image/jpg").replace("data:image/png;base64,","");
  
                  return(dataURL);
              }   
  
          };
  
          $("#output").append(dataStart);
  
          container.each(function(index,value){
              setTimeout( function() {
  
                  var deze = $(value) 
  
                  $("#output").append("{\"nr\" : \""+deze.attr("id")+"\", \"naam\" : \""+deze.attr("naam")+"\", \"cat\" : \""+deze.attr("cat")+"\"},");
  
                  kinderen = deze.find("li");
                  kinderen.each(function(i,v){
  
                      naam = $(this).parent().attr("id")+"_"+$(this).attr("class");
                      setTimeout(function(){
                          var img = $(v).find("img").get(0)
                          $("#output").append("{\"naam\": \""+ naam + "\", \"data\" : \"" + convertToBase64(img) + "\"},");
                      },i*speed);
  
                      $(this).hide();
                  });
  
                  console.log(index);
  
              }, index*speed*5);
  
              //if(index==100){return false;}
  
          });
  
      &lt;/script&gt;
  </code></pre>
  
  <p>when i run this is sort shuts down at 37 (index) and if i wait long enough is will finish. Can anybody tel me how to make it run more smooth?</p>
  
  <p>is there some javascriptfunction i overload, is there a form of cashe i dont no about, am i overworking the setTimeout function, am i overworking the dom, are my files to big. Any ideas. </p>