Loads javascript files based on an array of urls.
var mejl = function(a,b,c){with(document)for(;(c=createElement("script")).src=a.shift();body.appendChild(c))c.async=b}
Just throw it an array of URLs and a boolean for async ;-) Here's and example :
mejl([
'https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js',
'http://underscorejs.org/underscore-min.js',
'acme/core.js',
'acme/global.js',
'acme/mainpage.js'
], false);
Well, I don't know about your stuff but for my part I use it on a little one-page project like this :
- In dev mode my
index.js
file contains the function declaration and direct call to load each of my scripts - In prod mode my
index.js
file contains a minified and concatenated version of all theses scripts
These two versions are generated with a Makefile containing the scripts URLs. All I have to do is make
or make prod
This way I don't have to bother with different versions of the HTML file, I only include index.js
.
Created by Hubert Sablonnière (@hsablonniere) with help from @p01 and @tsaniel.
See the 140byt.es site for a showcase of entries (built itself using 140-byte entries!), and follow @140bytes on Twitter.
To learn about byte-saving hacks for your own code, or to contribute what you've learned, head to the wiki.
140byt.es is brought to you by Jed Schmidt, with help from Alex Kloss. It was inspired by work from Thomas Fuchs and Dustin Diaz.
Save another 4 bytes
function(a,b,c){with(document)for(;(c=createElement("script")).src=a.pop();body.appendChild(c))c.async=b}