0

I have a requirejs module that depends on jquery. Instead of loading jquery from a directory, I decided to add it statically in the webpage as a <script> entry from a CDN. requirejs however keeps attempting to load from file.

Is there a way of telling requirejs that a given dependency is added in the HTML and therefore it should not retrieve it?

Stefano Borini
  • 138,652
  • 96
  • 297
  • 431

1 Answers1

1

There's no configuration option to tell RequireJS that something is already loaded. However, you can create a fake jquery module that will just give access to the jQuery that you've already loaded through a script:

define("jquery", function () {
  return jQuery;
});

When I do something like this, I add this fake module just before my call to require.config. I find that it is a convenient place for it.

Also, make sure that the script element that loads jQuery appears before the script that loads RequireJS. Otherwise, jQuery will detect RequireJS and call define itself, and you'll get an error.

Louis
  • 146,715
  • 28
  • 274
  • 320