Aloha Editor some time ago made the switch to use requirejs to load plugins and language files dynamically. Using requirejs avoids the need to put all plugins and language files into the core aloha.js library, thereby reducing its size.
Although requirejs solves the dynamic loading problem, it also brings an unfortunate side-effect with it, which is particularly problematic considering that Aloha Editor is a library that is meant to be integrated into other applications.
The side-effect is that requirejs loads modules asynchronously. This forces applications integrating Aloha Editor to run in a callback. Aloha Editor suggests the following pattern:
Aloha.ready(function () { ... application code ... });
After integrating Aloha Editor into multiple applications I found that this can be very painful because it forces an additional level of indirection. In smaller applications, this could be handled by just wrapping the entire application with Aloha.ready(). In larger applications I found it easier to handle this on a case by case basis, which however litters the code with Aloha.ready()s and other callback mechanisms. Examples of what that looks like can be found in the Aloha Editor bootstrap file (Aloha.trigger).
There also was the problem when Aloha Editor was using an older version of requirejs. This made it difficult to use Aloha Editor in applications that used a newer version. Now that Aloha Editor has updated its version of requirejs, it is the other way round.
Although requirejs provides a feature that allows a library to use its own version of requirejs by rewriting the “define”s during compilation, that’s still less than ideal because it would mean having multiple versions of requirejs in a page (~6kb min+gz each), and it wouldn’t solve the problem for loading the development version of Aloha Editor inside an application (which is where I tend to spend most of my time).
I attempted to solve this problem with r.js, by implementing some hacks that made r.js output, not the concatenated version of the source code, but rather a sequence of document.writes that write <script> tags into the document. This document.write mechanism could be used during development to load Aloha Editor synchronously, which solved both the asynchronous loading problem, as well as the multiple requirejs versions problem. No change was necessary for loading the concatenated script in production since requirejs supports synchronous instantiation of modules when the module was already loaded (which is true in the case of Aloha Editor because you need to include at least the concatenated aloha.js manually via a script tag).
The r.js approach worked, but I wasn’t really satisfied with it. Too many hacks were necessary to make it work. Instead I wrote a minimal AMD loader implementation that encourages a single concatenated script loaded via a plain old script tag to be used in production, while for development a document.write approach is used.
This leaves us again with the problem that people have been trying to solve by using requirejs in the first place. I believe the solution to that problem should not be dictated by Aloha Editor. If an application uses requirejs, it can be solved with requirejs. If an application uses plain old script tags, it can be solved simply by including the right script tags.