A synchronous version of Require.js for use with optimized files produced using the Require.js AMD framework
Why would you need this?
Require-synchronous allows you load optimized code and then execute it immediately, where you need it.
The reason this library was written was to allow synchronous legacy code to be replaced with Require.js modules.
Why don't you make a pull request on the Require.js repository
I consider Require.js's asynchronous model to be superior to synchronous models and I wrote this basically to handle an edge case. I consider it a shim that doesn't have a place in Require.js's code base.
How do I use this?
- optimize your code using the Require.js optimizer
- save require-synchronous.min.js to your server
- change your page code to use require-synchronous.js instead of
require.js (note that
data-mainwill no longer work)
- load our optimized code at the point where you need it to be executed
require-synchronous temporarily overrides any existing methods called
declare() and restores them as soon as it is completed. This
means that at present it can only be used once (every time
invoked, the previous version of require will be restored.) If you find you
need to use this code several times on one page, you should probably consider
more serious architectural changes.