title: Load scripts if not already loaded, and then use them
body: <p>I have 4 javascript libraries I would like to load if the are not already loaded. Then, I want to use their functions.</p>
  
  <p>My problem is that I am getting <code>Uncaught ReferenceError: sbjs is not defined</code>, the scripts get loaded but I can't actually use them.</p>
  
  <p>I have it working perfectly to where it will add the scripts above the <code>&lt;/body&gt;</code> tag if they are not already loaded, but I can't seem to get them to work.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>&lt;script&gt;
      window.onload = myapp_scripts;
  
      function myapp_scripts () {
        var myapp_script;
  
        if (!window.jQuery) {
          myapp_script = document.createElement('script');
          document.body.appendChild(myapp_script);
          myapp_script.src = 'http://myapp.dev/js/jquery.min.js';
          console.log('load jquery');
        }
        if (!window.Cookies) {
          myapp_script = document.createElement('script');
          document.body.appendChild(myapp_script);
          myapp_script.src = 'http://myapp.dev/js/cookie.min.js';
          console.log('load cookies');
        }
        if (typeof url == 'undefined') {
          myapp_script = document.createElement('script');
          document.body.appendChild(myapp_script);
          myapp_script.src = 'http://myapp.dev/js/url.min.js';
          console.log('load url');
        }
        if (typeof sbjs == 'undefined') {
          myapp_script = document.createElement('script');
          document.body.appendChild(myapp_script);
          myapp_script.src = 'http://myapp.dev/js/sourcebuster.min.js';
          console.log('load sbjs');
        }
  
        myapp_init();
      }
  
      function myapp_init () {
          sbjs.init();
  
          console.log(Cookies.get('source_id'));
          console.log(url('source_id'));
          console.log(sbjs.get.current);
  
          $('#myapp_form').submit(function (event) {
              event.preventDefault();
              console.log('form submitted');
          });
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>How do I make it so I can also use the scripts I've loaded dynamically?</p>