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

时光总嘲笑我的痴心妄想 提交于 2019-12-23 09:32:19

问题


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.



来源:https://stackoverflow.com/questions/20100575/how-do-i-make-require-js-fetch-a-script-that-does-not-end-in-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!