We have a few problems in a project I am working on, where we have a lot of JavaScript files, where we have hardcoded URLs to controller actions.
In your case you need to pass urls to js code files from views with using url helpers. Modify your js files to use one of module pattern.
First way - importing of global variables:
js
(function (url) {
// your code
}(external_url));
view
Second way - exporting module:
var module = (function (url) {
// your code
}(external_url));
view