Last time I wrote about a possible require JS module for zend framework 2. After receiving a fair amount of interest, feedback and suggestions in general I decided to give it a go.

I proceeded to spend a decent amount of time reading all of requirejs’s documentation, mapping out how I’d like to fit that structure into the zend framework modular structure. It’s pretty much the same as described in the previous blog post, with only one big change… I’ve actually written the code. I know, shocker right.

So now what?

Well, I know this news might not be as interesting as I hoped it would be, but it is something. By publishing this blog post I’m hoping to receive more feedback, and perhaps some nice PRs. I’ve written some usage examples in the wiki in case you’re interested.


RequireJS (from here on RJS) did an awesome job supplying a modular structure. However, when working with ZF2 you’re already in a modular structure. This means we’re bound together with other modules if we want to share RJS modules. Every ZF2 module’s RJS module should have the possibility to get executed. Imagine having a RJS module that doesn’t get executed because the main application doesn’t know about it. That would take away a lot of flexibility.

I kept in mind that every module should share the same config map when it comes to loading RJS modules. This means that one way or another, we’ll still need a main application to provide all modules with this information.

SxRequireJs sets up a main application, which essentially sets all “module bootstraps” as a dependency, waits for them to load, and then executes them. This will be your module’s entry point, and should have its own dependencies.


Yes yes, I’ll stop talking. But I’d like to ask all of you to take a look, leave feedback and / or submit improvements.