Sunday, December 01, 2013

Client-side JavaScript Module Loading

Thank you Tom Dale for pointing out why RequireJS completely misses the point of requiring modules. While I agree with that assessment, there are better ways to store (unparsed) functions than as strings.

I am still hoping to find a library that takes a healthy approach to implementing require functionality for client-side JavaScript. If I don't find anything soon though, I will have to make one myself. Here are the key aspects I will require of... require:

  • Modules should be stored unparsed until required.
  • A require command will be null code if the module had already loaded.
  • A require command will parse the module and append it as a property of the current scope if it had not yet been loaded but is available to the client.
  • A require command will attempt to retrieve the module file via AJAX if it is not available to the client.
  • A require command will throw an error if the module is unavailable on both the client and the server.
  • The same require command will be parsed by the packager on the server side to compile the module into the distribution file.

Now back to my quest...

No comments: