Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make Require.js fetch a script that does not end in `.js`? [duplicate]

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?

like image 705
Javier Manzano Avatar asked Nov 20 '13 15:11

Javier Manzano


People also ask

How do I link two JavaScript files?

Answer: Use the export and import Statement Since ECMAScript 6 (or ES6) you can use the export or import statement in a JavaScript file to export or import variables, functions, classes or any other entity to/from other JS files.

How do I include an external js file in another JavaScript file?

To include an external JavaScript file, we can use the script tag with the attribute src . You've already used the src attribute when using images. The value for the src attribute should be the path to your JavaScript file.

Is it possible to dynamically load external JavaScript files in JavaScript?

Dynamic loadingThose files can be loaded asynchronously in JavaScript. To load a JavaScript file dynamically: Create a script element. Set the src , async , and type attributes.

How do you load a JavaScript script?

For loading a script file dynamically using JavaScript, the basic steps are: Create the script element. Set the src attribute on the script element to point to the file we want to load. Add the script element to the DOM.


1 Answers

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.

like image 170
qwertynl Avatar answered Sep 30 '22 10:09

qwertynl