I have inherited of an application and need to reorganize and I hope I will be able to modularize the tons of Javascript that is everywhere.
It is a multi-page webapp. Each page has a script tag in the header, which currently contains a DomReady handler which initializes all user event handlers for that specific page, and also very often contains from 1 to 10 javascript functions that are specific to this page (meaning they are not useful anywhere else in the app).
Then, there is a jQuery import on every page, plus an import of somthing like App.js which is simply a very large collection of global functions which are useful in many different pages of the application.
Page of the application are quite different one from another, so it seems to make sense not to make every page load everything.
I'm desperately trying to organize all this, and after investigating modern solutions like RequireJS, Browserify, simple lightweight MVP frameworks like Riot.js, loose coupling through Mediator pattern and so on.
A lot of these seem to target single-page web applications mainly.
I'm having a hard time to imagine how to reorganize this 40 page application where almost every page needs a separate initialization, a few specific functions and a large number of general ones...
Also, the webapp can be installed on a user's own server and individual page scrips behaviour must be customizable through overriding some of the functions (or adding to the initialization, or the modules if they become modules in the future).
What would an JS expert do ?