View on GitHub

What JS-Class-Loader is

Brief

JS-Class-Loader reads a codebase of javascript class files and generates a single module file of code. It uses name and folder conventions to detect dependencies and automatically put the code into the correct order.

It is written in Java (and is simple to integrate with Java web apps) but is also useful with static web sites (you can use it in your IDE), other scripting languages or any build tool.

Less brief

Developers working on large javascript codebases will know that if you are writing serious amounts of javascript your codebase can very quickly get messy and become hard to manage. Things that work for a rapid prototype often turn into a mess when the codebase grows. This tool imposes code conventions that keep your code neat, clean and easy to manage no matter how large it gets. It uses these conventions to detect dependencies and bundle your code for you, so that you can add, remove and refactor code and files without having to do anything to your script tags. It is fast enough even on large codebases that it allows you to make a change, reload the browser and see the change.

If your project is a java webapp already then this tool will integrate seamlessly as either a runtime servlet or a build time task. If your project is any other sort of application then you can use JS-Class-Loader from your IDE or your build to manage your javascript code quickly and simply.

Principles

JS-Class-Loader was designed with the following requirements in mind:

Rules of JS-Class-Loader

  1. Class names must match file names
    Whether it's a class, a static object, a function or anything else, the thing in the file must match the name of the file. This is so that when you reference the thing, JS-Class-Loader knows to include the file.
  2. Folder structure must match package structure
    This is the tried and tested code convention that Java uses, and allows you to separate your code into modules and groupings. You can still have that big messy util file in the root namespace if you want but JS-Class-Loader allows and encourages you to use proper code structure in your javascript.
  3. File names must not have extra dots in them
    JS-Class-Loader uses dots for namespaces and gets confused when a filename has dots in it. This may be fixed in future (by converting them to underscores) but for now, no dots in filenames apart from the .js extension. (dashes and underscores in filenames are ok though, we recommend converting dots to underscores)

Having said that, you can still include files, 3rd party libraries and modules in your bundle that don't conform to this scheme. You just need to explicitly include them in your code somewhere, you can't just rely on dependency detection to work out that you need them. There are plenty of examples in this site of how to include the most common js frameworks and libraries in your codebase