RequireJS文本插件添加';。js';文件名,但在同一域上
我使用文本插件优化了RequireJS设置。我似乎遇到了添加到模块中的“.js”文件名。我在Firefox17中看到了这一点 我读了这篇文章,但我很确定我的所有文件都在同一个域上。 我的文件位于RequireJS文本插件添加';。js';文件名,但在同一域上,requirejs,requirejs-text,Requirejs,Requirejs Text,我使用文本插件优化了RequireJS设置。我似乎遇到了添加到模块中的“.js”文件名。我在Firefox17中看到了这一点 我读了这篇文章,但我很确定我的所有文件都在同一个域上。 我的文件位于 dev-img4.x.com/m/j/mains/main-article.js dev-img4.x.com/m/j/views/logged_out.js dev-img4.x.com/m/j/views/templates/logged_out.html 文本插件试图查找dev-img4.x
- dev-img4.x.com/m/j/mains/main-article.js
- dev-img4.x.com/m/j/views/logged_out.js
- dev-img4.x.com/m/j/views/templates/logged_out.html
require.config({
baseUrl: 'dev.x.com/m/j',
paths: {
'jquery': 'dev.x.com/m/j/lib/jquery',
'backbone': 'dev.x.com/m/j/lib/backbone',
'underscore': 'dev.x.com/m/j/lib/underscore',
'text': 'dev.x.com/m/j/lib/text'
},
shim: {
'underscore': {
exports: '_'
},
'backbone': {
deps: ['jquery', 'underscore'],
exports: 'Backbone'
}
},
urlArgs: 'buildlife=1',
waitSeconds: 15
});
require(['jquery', 'modules/site', 'underscore', 'backbone', 'views/logged_out'], function($, site, _, Backbone, loggedOutView) {
//This function will be called when all the dependencies
//listed above are loaded. Note that this function could
//be called before the page is loaded.
//This callback is optional.
var loggedOutBar = new loggedOutView();
/* Initialize code */
$(document).ready(function() {
/* sitewide code */
site.init();
$('.rslogo').after(loggedOutBar.render());
});
}
);
logged_out.js
define(['module', 'jquery', 'underscore', 'backbone', 'text!views/templates/logged_out.html'], function(module, $, _, Backbone, loggedOutTemplate) {
/* Create a view of the logged out bar */
var loggedOutView = Backbone.View.extend({
className: 'loginbar',
initialize: function() {
},
template: _.template(loggedOutTemplate),
render: function() {
this.$el.html(this.template);
return this; /* Allow method chaining after render */
}
});
return loggedOutView;
});
logged_out.html
<a href="#" class="signin">Sign In</a> | <a href="#" class="signup">Sign Up</a>
|
使用相对URL,您只需
baseUrl: '/j/'
然后,对于配置中的每个js文件,您只需要从baseUrl恢复
jquery: lib/jquery
这将防止在dev.x的子域上使用require时可能出现的任何跨域问题
另外,如果您正在访问www.dev.x(dev.x的子域),这可能会导致添加“.js”的问题。用户“liorix”在上一篇文章中发现了此问题:
如果这是一个问题,将baseUrl设置为相对将解决您的问题。没有www.dev.x.com域,因此我将尝试使用相对路径。谢谢。我不能使用相对路径。我有一个奇怪的服务器设置,我无法控制/j目录不直接脱离域名的位置:(