0

I know that for design reasons requirejs doesn't offer a way to load itself in noContext mode, bound to a different variable. Is it possible to do this manually somehow, or does require utilize the specific word "require" to execute its code? I know that it needs to the "require" and "requirejs" global variables to work - is it possible to change these names?

A little context: I am building Chrome extension which needs to load requireJS on a page to load a decent number of modules. However, some pages (upworthy.com and slate.com being 2 prominent examples) have critical functionality already bound to the name "require" (in the case of upworthy, they use requirebin or browserify). So I want to load requireJS without interfering with whatever native functionality is already assigned to require.

AlexZ
  • 11,515
  • 3
  • 28
  • 42

1 Answers1

1

The JavaScript execution environment of content scripts are separated from the page, so you should not have any namespace collisions.

If you really need to inject the script in the page, then I strongly recommend to use r.js to generate one single JavaScript file, wrapped in an anonymous self-invoking function. Then, the require variable of your script will not conflict with the one in the page.

Community
  • 1
  • 1
Rob W
  • 341,306
  • 83
  • 791
  • 678
  • How can I load the requireJS file without injecting it into the header? I can't find any info on how to load it using XHR... – AlexZ Mar 23 '14 at 11:24
  • Damn Rob, you've answered enough of my questions on here that I should credit you as a code contributor or something. Much thanks! – AlexZ Mar 23 '14 at 11:27