How do I make Require.js fetch a script that does

2019-06-19 18:28发布

问题:

This question already has an answer here:

  • Is it possible to stop requireJS from adding the .js file extension automatically? 3 answers

I'm developing an app that uses a certain site to make payments easier, and the way it handles payments requires to import some javascript from this url https://bridge.paymill.com/ that contains the script.

The fact is, I'm using require js to load all the scripts, in my main.js configuration, I'm trying to make it this way:

requirejs.config({
  ...
  'paymill': 'https://bridge.paymill.com/',
  ...
});

But this, of course, tries to fetch from https://bridge.paymill.com/.js, which is not the correct url (it's without the last .js)

How could I notify requirejs to load this without appending '.js' at the end?

回答1:

Put a question mark at the end of the URL

requirejs.config({
  ...
  'paymill': 'https://bridge.paymill.com/?',
  ...
});

How this works:

https://bridge.paymill.com/?.js is a valid URL with .js as a GET request.