Overcoming RequireJS's '.js' extension adding in cache/proxy environments

拟墨画扇 提交于 2019-12-11 21:00:36

问题


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

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