How to load scripts first when needed with require.js?

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){
    //...
})

This is a great guide for marrying Backbone.js and Require.js:

http://backbonetutorials.com/organizing-backbone-using-modules/

链接地址: http://www.djcxy.com/p/66828.html

上一篇: 构建backbone.js应用程序

下一篇: 如何在需要时使用require.js首先加载脚本?