Requirejs encourages using module IDs instead of URLs for script tags, it loads all codes relative to baseUrl. RequireJS also assumes by default that all dependencies are scripts, so it does not expect to see a trailing ".js" suffix on module IDs.
However, there may be times when you do want to reference a script directly and not conform to the "baseUrl + paths" rules for finding it. For instance, we want to add cache bust to the URL for specific js files rather than all js files (through urlArgs config option).
If a module ID has one of the following characteristics, the ID will not be passed through the "baseUrl + paths" configuration, and just be treated like a regular URL that is relative to the document:
- Ends in ".js".
- Starts with a "/".
- Contains an URL protocol, like "http:" or "https:".
var i18nModule = 'i18n!/scripts/customize/nls/lang.js?v=4.0';Above example tells requirejs NOT conform to baseUrl+paths rule, instead load the lang.js file directly using relative path to document (root path). Note that i18nModule variable starts with a "/", and also ends in ".js".
require([i18nModule], function(obj) {
// process the loaded file
});
No comments:
Post a Comment