require.js文本插件添加" .js文件"在文件名 [英] require.js text plugin adds ".js" to the file name

查看:98
本文介绍了require.js文本插件添加" .js文件"在文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用requirejs和文字插件工作,我有奇怪的问题。

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

我有两个Web服务器:

I have two web servers:


  1. 本地主机:3000 - 作为CDN并拥有所有静态文件:JS,图片,CSS和模板

  2. 本地主机:3001 - 服务器 - 作为REST服务器和服务只有一个文件,该文件main.html中

  1. localhost:3000 - act as CDN and has all the static files: js, images, css and templates
  2. localhost:3001 - server - act as REST server and serve only one file, the main.html file

在main.html中文件加载所有的 JS 使用下面的行从第二个服务器文件:

The main.html file loads all the js files from the second server using the following line:

<script data-main="http://localhost:3000/js/main" 
        src="http://localhost:3000/lib/require-jquery.js"></script>

由于某些原因,当使用的 requirejs文本插件后,他增加了模板JS导航到时候后缀的本地主机:3001

For some reason, when using the requirejs text plugin, he adds to the templates ".js" suffix when navigating to localhost:3001

我使用的语法如下:

define ['jquery','backbone','underscore','models/model','text!templates/main.html', 
        'views/navigation', 'views/player', 'views/content', 'views/header']

当我浏览到的本地主机:3000 正常工作

你能想到的任何原因,文本插件将不得不从远程服务器(例如,CDN服务器)提供的文本文件的问题?

Can you think of any reason that the text plugin would have problems serving text files from a remote server (for example, CDN server)?

推荐答案

我已经挖文本插件的code。

I've digged in the code of the text plugin.

我发现该文本插件假定开发商转换的文本模板到HTML,因为它驻留在不同的域。

I've found out that the text plugin assumes that the developer converted the text template to html since it resides on a different domain.

我已经更改文本插件的code不承担它。

I've change the code of the text plugin to not assume it.

有人认为我做错了什么?

Someone thinks that I'm doing something wrong?

插件的原始code:

            //Load the text. Use XHR if possible and in a browser.
            if (!hasLocation || useXhr(url, defaultProtocol, defaultHostName, defaultPort)) {
                text.get(url, function (content) {
                    text.finishLoad(name, parsed.strip, content, onLoad, config);
                });
            } else {
                //Need to fetch the resource across domains. Assume
                //the resource has been optimized into a JS module. Fetch
                //by the module name + extension, but do not include the
                //!strip part to avoid file system issues.
                req([nonStripName], function (content) {
                    text.finishLoad(parsed.moduleName + '.' + parsed.ext,
                                    parsed.strip, content, onLoad, config);
                });
            }

这篇关于require.js文本插件添加&QUOT; .js文件&QUOT;在文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆