title: Replace loaded javascript with newly loaded one in head
body: <p>I have web page which loads the javascript on when below function get calls.</p>
  
  <pre><code>loadjavascript:function(v_url) 
      {
          if (v_url != indef &amp;&amp; v_url != ' ') {
  
              var filename = '../includes/javascript.php?url=' + v_url;
  
              var fileref=document.createElement('script');
                  fileref.setAttribute("type","text/javascript");
                  fileref.setAttribute("src", filename);
              if (typeof fileref!="undefined")
                  document.getElementsByTagName("head")[0].appendChild(fileref);
          }   
      }
  </code></pre>
  
  <p>When i check in firebug i can see so many same javascripts loaded in.</p>
  
  <p>To resolve this issue what i want to do is -</p>
  
  <p>1) When the function get called if javascript is not loaded then load it and append to head.
  2) If function is called and it is same javascript which is already present in the head section then dont load the new one <strong>but to run the already present javascript</strong>.</p>
  
  <p>Can it be done or it is not possible in javasctript..Could anyone please share some ideas how to do it..</p>
  
  <p>thank you in advance. </p>