Questions tagged [requirejs]

RequireJS is a JavaScript file and module loader. It is optimized for in-browser use, but it can be used in other JavaScript environments, like Rhino and Node.js. If you are using the require call that comes bundled with Node.js then you are NOT using RequireJS. Please do not use this tag for such cases. Use the require tag instead.

RequireJS is a JavaScript file and module loader. It is optimized for in-browser use, but it can be used in other JavaScript environments, like Rhino and Node.js. If you are using the require call that comes bundled with Node.js then you are not using RequireJS. Please do not use this tag for such cases. Use the tag instead.

It uses the Asynchronous Module Definition (AMD) API and also supports loader plugins.

Browser Support

  • Internet Explorer 6+
  • Firefox 2+
  • Safari 3.2+
  • Chrome 3+
  • Opera 10+

Links:

7726 questions
899
votes
6 answers

Relation between CommonJS, AMD and RequireJS?

I'm still very confused about CommonJS, AMD and RequireJS, even after reading a lot. I know that CommonJS (formerly ServerJS) is a group for defining some JavaScript specifications (i.e. modules) when the language is used outside the browser.…
gremo
  • 47,186
  • 75
  • 257
  • 421
450
votes
14 answers

Does it make sense to use Require.js with Angular.js?

I'm a newbie to Angular.js and trying to understand how it's different from Backbone.js... We used to manage our packages dependencies with Require.js while using Backbone. Does it make sense to do the same with Angular.js?
Franck
  • 4,575
  • 3
  • 15
  • 4
317
votes
5 answers

When should I use require() and when to use define()?

I have being playing around with requirejs for the last few days. I am trying to understand the differences between define and require. Define seems to allow for module separation and allow for dependency ordering to be adhere. But it downloads…
skinnybrit51
  • 4,927
  • 7
  • 25
  • 28
304
votes
12 answers

Prevent RequireJS from Caching Required Scripts

RequireJS seems to do something internally that caches required javascript files. If I make a change to one of the required files, I have to rename the file in order for the changes to be applied. The common trick of appending a version number as…
BumbleB2na
  • 10,723
  • 6
  • 28
  • 30
248
votes
2 answers

Excluding files/directories from Gulp task

I have a gulp rjs task that concatenates and uglifies all my custom .JS files (any non vendor libraries). What i am trying to do, is exclude some files/directories from this task (controllers and directives). Heres my tree: - application -…
Oam Psy
  • 8,555
  • 32
  • 93
  • 157
173
votes
6 answers

Loading Backbone and Underscore using RequireJS

I'm trying to load Backbone and Underscore (as well as jQuery) with RequireJS. With the latest versions of Backbone and Underscore, it seems kind of tricky. For one, Underscore automatically registers itself as a module, but Backbone assumes…
Aaronius
  • 4,936
  • 6
  • 31
  • 40
169
votes
2 answers

What is 'define' used for in JavaScript (aside from the obvious)?

I have searched high and low for documentation on this, but I just cannot find anything anywhere. I am using Aloha and want to use their sidebar prototype to create a new side bar of my own attached to other plugin functionality. Their sidebar.js…
David O'Sullivan
  • 2,969
  • 4
  • 21
  • 24
147
votes
8 answers

Mismatched anonymous define() module

I'm getting this error when I browse my webapp for the first time (usually in a browser with disabled cache). Error: Mismatched anonymous define() module: function (require) { HTML: . . .
Adonis K. Kakoulidis
  • 4,951
  • 6
  • 34
  • 43
141
votes
6 answers

Why use Object.prototype.hasOwnProperty.call(myObj, prop) instead of myObj.hasOwnProperty(prop)?

If I understand correctly, each and every object in JavaScript inherits from the Object prototype, which means that each and every object in JavaScript has access to the hasOwnProperty function through its prototype chain. While reading RequireJS'…
timkg
  • 1,773
  • 2
  • 14
  • 12
138
votes
4 answers

What's the difference between Require.js and simply creating a