I hereby decree

by David LeMieux

 

I've been working on a side project of sorts. What makes this one different is that I don't know where it will take me. I would like to introduce Cigar.js - a JavaScript dependency importer. Basically, it acts kind of like import does in Java, but it works client side and it is for adding JavaScript files to your runtime environment.

It works like this: After loading the Cigar.js file you can call _import and load javascript files from your own domain (for now, though I do hope to add the ability to do external files as well). You can chain the imports together, essentially creating a queue of files to load. At the end you can specify a callback that will be initialized once all the files have been loaded.

I've had this idea in the my head for a while now, but it wasn't until I saw a tweet from Jeff Remer that I thought "well, Groucho always has a cigar, so I should make a js library called 'cigar'."

Jeff's Groucho Tweet
Yeah, it was all based on a bad pun

What is emerging from this wandering idea of mine is that you could use this to structure your JavaScript files more like Java classes. This could be handing for creating reusable code snippets and have dependencies, but help remove all the circular references.

You could have a utility "class" called "AwesomeUtility" that is used in "Object1" and "Object2". Cigar would allow you to save those in separate js files and test them independently, then you can use Cigar to import them in to your main script file and the dependency will only be loaded once.

As it is, Cigar is no-where near production ready. There is still a lot to test out and play with. Also, I have know idea where this is going.

 

blog comments powered by Disqus