Reputation:
Background
I have a long list of models and views made with backbone.js - but not all users will open all views. I use require.js to load JavaScripts files and templates.
What I have now
I have a router that knows about all views. Since the router know this, all views, models and templates are therefore loaded at startup - this also loads randomly visited views.
Problem
How can I use require.js to load the JavaScripts when needed? Not in the initial startup, but when user first opens a view.
UPDATE I can now get this working as commented in answer below.
In router I have a require per route:
require(["yourmodule"], function(MyModule){
//...
})
Upvotes: 6
Views: 909
Reputation: 48127
This is a great guide for marrying Backbone.js and Require.js:
http://backbonetutorials.com/organizing-backbone-using-modules/
Upvotes: 5