问题
RequireJS automatically adds a '.js' extension to each module name, and a known hack is to add a ? at the end, as detailed here and here.
The problem is, that adding a question mark means cache and proxy servers will usually conclude these are dynamic files and not cache them. I guess it's configurable if I control these cache/proxy servers but between my server and the client there is potentially a downstream of proxy servers in between which is beyond my control.
So, is there any other way to cause RequireJS to not add the .js extension other than putting a question mark?
回答1:
There is no way to configure require.js to achieve what you want. But you can override require.load method and make url preprocessing
require.load = (function(load) {
var stripJSRegex = /\.js$/;
return function(context, moduleName, url) {
load.call(this, context, moduleName, url.replace(stripJSRegex, ''));
}
})(require.load);
来源:https://stackoverflow.com/questions/24520925/overcoming-requirejss-js-extension-adding-in-cache-proxy-environments