I just started working with Require.JS, and I'm a little unclear in the relevant cases in which it should be used, as well as in the correct way to use it in these cases.
This is how I currently have things set with Require.JS. I have two functions: functionA() and functionB() . Both of these functions require an additional functionC() to work properly.
I only want to load the C () function when necessary, i.e. when function A () or functionB () will be called. Therefore, I have the following files:
functionC.js
functionC(){ //do stuff }
functionA.js
functionA(){ define(['functionC'],function(){
functionB.js
functionB(){ define(['functionC'],function(){
So, is this configured correctly? And if I end up calling functionsA () and functionB () on the same page, is that extra work being done as they both load the functionsC.js file? If so, is this a problem? And if so, is there a way to set it up so that they first check if the function.js file has been loaded yet, and load it if it hasn't been? Finally, is this a suitable use of Require.JS?
javascript requirejs
maxedison Jan 22 '11 at 10:24 2011-01-22 22:24
source share