I am trying to use require.js for loading js scripts simply using firebug console.
If I try the following code it works:
var script = document.createElement("script");
script.src = "http://127.0.0.1/~myName/myPublic/js/lib/require.js";
document.body.appendChild(script);
setTimeout(function() {
require(["lib/jquery-1.7.1"], function() {
console.log("test: ", $.fn); // **** it gives me the expected result *****
});
}, 1000);
Now I would like to load all the js files present in http://127.0.0.1/~myName/myPublic/js/lib/
setTimeout(function() {
require.config({
"packages": ["lib"]
});
require(["lib"], function() {
console.log("test: ", $.fn);
});
}, 1000);
but I get the following error:
Load timeout for modules: lib http://requirejs.org/docs/errors.html#timeout
What is wrong about the code using require.conf?
P.S.:
I run the code from http://127.0.0.1/~myName/myPublic/js/
I’ve never used require.js before, but something caught my eye – how would require.js on the client side know to fetch every *.js file in your directory?
Looking at the documentation, looks like require.js automatically loads a “main.js” if you specify the package. Thus, it will look for http://127.0.0.1/~myName/myPublic/js/lib/main.js. Furthermore, according to your config, it may additionally look for http://127.0.0.1/~myName/myPublic/js/lib/lib.js
If you really want to see how it works, try installing a packet sniffer like wireshark or charles. See what sort of requests the client (browser) is making to search for the javascript files.
Unfortunately, I don’t know how to fix your config — the documentation on require.js for packages seems to be straight up wrong or I’m just not following it correctly.