- Make sure that I only included the library on the pages that needed it. – This wouldn’t work very well because my users could create new pages based on my template. Some would need the library and some would not.
Script tag injection is nothing new, it’s been around for a long time. Neither are dynamic script loaders. YUI has had one for years, renamed to “get” in YUI3, that I’ve used quite a few times. LabJS and Require.JS are both full featured, well supported script loaders and work great in a wider variety of use cases. NBL was recently updated.
So why did I bother making this one?
Well, it’s really not that hard to do for one thing. I love making micro-libraries like this. It has no external dependencies and the list of possible features I’d like to add is very short.
What I really wanted to do was be able to modify and existing script to dynamically load a script it was dependent on. I could see doing this in several different pages, so I put it in a library.
bootstrap("myLibrary.js", "ScriptTagId"); //or $b("myLibrary.js","ScriptTagId");
The road map looks a little bit like this.
- Add a “script loaded” event or , more likely, allow a callback to be passed in and executed once the script has loaded.
- Add the ability to dynamically load CSS files
- make the “script tag id” parameter an optional parameter and auto-generate an ID if none is provided
- Make a cool icon for the project
So, to summarize, this library is really simple. The code is easy to understand right now. I believe is releasing early and releasing often. I didn’t want the lack of features to stop me from releasing. 😉
The code is licensed under the Apache 2.0 license.
How simple could it be? Lemme post the source code for you.