Skip to content

Instantly share code, notes, and snippets.

@jonathanstark
Last active September 29, 2021 06:48

Revisions

  1. jonathanstark revised this gist Feb 20, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions adding-js-programmatically.html
    Original file line number Diff line number Diff line change
    @@ -15,11 +15,11 @@
    doc.body.appendChild(scriptTag);
    }
    }
    var awesomeBrowser = function() {
    var goodBrowser = function() {
    // Return true if browser passes all feature tests
    return true;
    }
    if(awesomeBrowser()) {
    if(goodBrowser()) {
    appendScripts([
    './js/script1.js',
    './js/script2.js'
  2. jonathanstark revised this gist Feb 20, 2013. 1 changed file with 10 additions and 10 deletions.
    20 changes: 10 additions & 10 deletions adding-js-programmatically.html
    Original file line number Diff line number Diff line change
    @@ -6,26 +6,26 @@

    <!-- Append javascript programatically so we don't make needless http requests -->
    <script>
    (function(){
    (function(doc){
    var appendScripts = function(srcs) {
    if (srcs.length > 0) {
    var scriptTag = document.createElement('SCRIPT');
    scriptTag.src = srcs.shift();
    if (src = srcs.shift()) {
    var scriptTag = doc.createElement('SCRIPT');
    scriptTag.src = src;
    scriptTag.onload = function(){appendScripts(srcs)};
    document.body.appendChild(scriptTag);
    doc.body.appendChild(scriptTag);
    }
    }
    var lameBrowser = function() {
    // Do checks and return true if browser is lame
    return false;
    var awesomeBrowser = function() {
    // Return true if browser passes all feature tests
    return true;
    }
    if(!lameBrowser()) {
    if(awesomeBrowser()) {
    appendScripts([
    './js/script1.js',
    './js/script2.js'
    ]);
    }
    })();
    })(document);
    </script>
    </body>
    </html>
  3. jonathanstark revised this gist Feb 20, 2013. 1 changed file with 8 additions and 8 deletions.
    16 changes: 8 additions & 8 deletions adding-js-programmatically.html
    Original file line number Diff line number Diff line change
    @@ -7,20 +7,20 @@
    <!-- Append javascript programatically so we don't make needless http requests -->
    <script>
    (function(){
    var append_scripts = function(srcs) {
    var appendScripts = function(srcs) {
    if (srcs.length > 0) {
    var script_tag = document.createElement('SCRIPT');
    script_tag.src = srcs.shift();
    script_tag.onload = function(){append_scripts(srcs)};
    document.body.appendChild(script_tag);
    var scriptTag = document.createElement('SCRIPT');
    scriptTag.src = srcs.shift();
    scriptTag.onload = function(){appendScripts(srcs)};
    document.body.appendChild(scriptTag);
    }
    }
    var lame_browser = function() {
    var lameBrowser = function() {
    // Do checks and return true if browser is lame
    return false;
    }
    if(!lame_browser()) {
    append_scripts([
    if(!lameBrowser()) {
    appendScripts([
    './js/script1.js',
    './js/script2.js'
    ]);
  4. jonathanstark renamed this gist Feb 15, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. jonathanstark created this gist Feb 15, 2013.
    31 changes: 31 additions & 0 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    <html>
    <head></head>
    <body>

    <!-- All your kewl content goes here -->

    <!-- Append javascript programatically so we don't make needless http requests -->
    <script>
    (function(){
    var append_scripts = function(srcs) {
    if (srcs.length > 0) {
    var script_tag = document.createElement('SCRIPT');
    script_tag.src = srcs.shift();
    script_tag.onload = function(){append_scripts(srcs)};
    document.body.appendChild(script_tag);
    }
    }
    var lame_browser = function() {
    // Do checks and return true if browser is lame
    return false;
    }
    if(!lame_browser()) {
    append_scripts([
    './js/script1.js',
    './js/script2.js'
    ]);
    }
    })();
    </script>
    </body>
    </html>