Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is requirejs trying to append a '.js' to .jst template files that are loaded with the !text plugin?

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']
  }
});
like image 426
B Robster Avatar asked Jul 06 '12 08:07

B Robster


1 Answers

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

like image 62
jrburke Avatar answered Oct 26 '22 23:10

jrburke