javascript - Executing code before document.ready in requirejs -
i see require.js
has support execute code when document.ready()
fired. see: http://requirejs.org/docs/api.html#pageload
i wondering there way 100% execute code before document.ready()
invoked? example, code main.js executed before document.ready() event? thanks.
there no pure requirejs solution request. in essence asking is:
i'd a) load modules asynchronously b) want load them synchronously.
requirement a
entailed fact using requirejs. requirejs loader designed load amd modules. amd stands asynchronous module definition. if use requirejs, have okay fact operates asynchronously. cannot guarantee module load , execute before document ready.
requirement 'b' entailed requirement code executes before document ready. cannot done otherwise forcing execution of modules synchronous. (i've given thought ways delay ready
event don't see being possible. solutions jquery.holdready
not really delaying event delaying handlers set using jquery.ready
. event still happens whenever browser decides happens handlers fired later. , jquery handlers affected, nothing else.)
you can load code using script
elements (that don't use async
attribute) won't using requirejs.
a solution give similar requirejs use almond. code have built single bundle. , load bundle synchronously. have same effect using script
elements still benefit modularization. note almond comes series of limitations. you'll have decide whether these limitations problem you. i've explained how use almond synchronously in answer.
Comments
Post a Comment