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

With define you register a module in require.js that you can then depend on in other module definitions or require statements.
With require you “just” load/use a module or javascript file that can be loaded by require.js.
For examples have a look at the documentation

My rule of thumb:

  • Define: If you want to declare a module other parts of your application will depend on.

  • Require: If you just want to load and use stuff.

Leave a Comment