6

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/common':['jquery']
  }
});
B Robster
  • 40,605
  • 21
  • 89
  • 122
  • Looking at the require.js documentation here: http://requirejs.org/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 Jul 06 '12 at 08:49

1 Answers1

9

I 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.com/requirejs/text#xhr-restrictions

jrburke
  • 6,776
  • 1
  • 32
  • 23