I use a .jst extension for template files, and load these with the requirejs text! plugin. E.g.,
define([
'jquery',
'backbone',
'underscore',
'text!templates/MyView.jst'
],
function($, Backbone, _, templateText) {
return Backbone.View.extend({
template: _.template(templateText),
initialize: function() {
},
render: function() {
}
});
});
This works swell when I test locally. However, when I try to do this after I've deployed my static files to AWS (the dynamic portions of the app run on Heroku), it fails to load the .jst files and appears to be trying to append a .js to their url's.
For reference, here's my requirejs config (from main.js)
requirejs.config({
paths: {
//directories
plugins: "lib/plugins",
//libs
jquery: "lib/jquery/1.7.1/jquery",
underscore: "lib/underscore/1.3.3/underscore",
backbone: "lib/backbone/0.9.2/backbone",
moment: "lib/moment", // date lib
//require plugins
text: "lib/require/plugins/text",
domReady: "lib/require/plugins/domReady"
},
shim: { //specify all non-AMD javascript files here.
backbone: {
deps: ['underscore', 'jquery'],
exports: 'Backbone'
},
underscore: {
exports: '_'
},
moment: {
exports: 'moment'
},
'plugins/jquery.colorbox': ['jquery'],
'util/jquery.dropTree':['jquery'],
'util/mon':['jquery']
}
});
I use a .jst extension for template files, and load these with the requirejs text! plugin. E.g.,
define([
'jquery',
'backbone',
'underscore',
'text!templates/MyView.jst'
],
function($, Backbone, _, templateText) {
return Backbone.View.extend({
template: _.template(templateText),
initialize: function() {
},
render: function() {
}
});
});
This works swell when I test locally. However, when I try to do this after I've deployed my static files to AWS (the dynamic portions of the app run on Heroku), it fails to load the .jst files and appears to be trying to append a .js to their url's.
For reference, here's my requirejs config (from main.js)
requirejs.config({
paths: {
//directories
plugins: "lib/plugins",
//libs
jquery: "lib/jquery/1.7.1/jquery",
underscore: "lib/underscore/1.3.3/underscore",
backbone: "lib/backbone/0.9.2/backbone",
moment: "lib/moment", // date lib
//require plugins
text: "lib/require/plugins/text",
domReady: "lib/require/plugins/domReady"
},
shim: { //specify all non-AMD javascript files here.
backbone: {
deps: ['underscore', 'jquery'],
exports: 'Backbone'
},
underscore: {
exports: '_'
},
moment: {
exports: 'moment'
},
'plugins/jquery.colorbox': ['jquery'],
'util/jquery.dropTree':['jquery'],
'util/mon':['jquery']
}
});
Share
Improve this question
edited Dec 15, 2012 at 16:30
B Robster
asked Jul 6, 2012 at 8:11
B RobsterB Robster
42.1k24 gold badges92 silver badges124 bronze badges
1
- Looking at the require.js documentation here: requirejs/docs/api.html#config-baseUrl its looking like it may be a cross-domain issue. Can someone confirm this is the case? (feel free to take it as an answer if it definitively is). If this is the case, its an obscure way to handle it. I initially though that the templates only had to be on the same domain as the JS files, but it seems to have to be on the same domain as the page itself. Looks like I may have to move forward with developing the next step (running everything through the r.js optimizer) before I can get this to work. – B Robster Commented Jul 6, 2012 at 8:49
1 Answer
Reset to default 9I just updated the text.js README with info that explains this issue. It is basically a way to use text resources across domains, but it requires a build. There is a way to override. Details here:
https://github./requirejs/text#xhr-restrictions
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744706501a4589085.html
评论列表(0条)