RequireJS - a few questions

sorry I was a little lazy and didn't try it all myself, but I thought a good answer to Stackoverflow could help some other guys too. I am considering whether or not to use requireJSto load my modules. I am currently doing this on my own, so I have some questions about requireJS.

  • How does requireJS deal with multiple links (it caches files / modules)?

More precisely, if you have type calls require(["some/module", "a.js", "b.js"], function...});, and you again refer to a.jseither b.jsin subsequent calls .requireor .definecalls , how does requireJS handle them? I assume this completely ignores these sitelinks, is this true? If so, is it possible to force JS to reload the script?

  • Is it always necessary to send files via wire or can you load modules statically?

I usually do to merge all my js files (including modules), with the exception of those that need to be loaded depending on the execution conditions. As far as I read the requireJS document, you can define proper names for the modules. So my question is: can you load a module that is already in the script without passing it over the wire? As far as I understand the document, names are created automatically for the modules based on their path location and file name, so this does not make sense for my requirement here.

+5
source share
2 answers

require.js. require.js , . require .

. (, , , - ), .

, , " ". , . : , - :

define(['moduleA', 'moduleB', 'moduleC'], function (a, b, c) {
    ...
    return exports;
});

exports , , , . , - :

define(['moduleA', 'moduleB', 'moduleC'], function (a, b, c) {
    ...
    return {moduleA: a, moduleB: b, moduleC: c};
});

.

, . .

, , .

+3

requirejs.undef()

+5

All Articles