require.js text plugin adds “.js” to the file name

后端 未结 7 1093
旧时难觅i
旧时难觅i 2021-01-08 00:31

I\'m trying to work with requirejs and text plugin and I have weird problem.

I have two web servers:

  1. localhost:3000 - act as CDN and h
7条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-08 00:53

    The documentation of the text plugin gives a hint to the solution: It's possible to configure the plugin in a way that it always fetches remote resources via XHR without appending the .js suffix and loading it via script tag. The simple solution is to always enforce using XHR:

    requirejs.config({
       config: {
          text: {
             useXhr: function (url, protocol, hostname, port) {
                return true;
             }
          }
       }
    });
    

    Note that the remote server needs to set the correct CORS header and that this could be a security issue. Thus add the necessary checks for trusted urls when using this instead of simply returning true.

提交回复
热议问题