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

Background

I have a long list of models and views made using backbone.js - but not all users will open all kinds. I use require.js to load JavaScripts files and templates.

What i have now

I have a router that knows about all the views. Since the router knows this, all views, models, and templates are loaded at startup - it also loads randomly viewed views.

Problem

How can I use require.js to load JavaScripts when necessary? Not in the initial launch, but when the user first opens the view.

UPDATE Now I can get this work to comment in response below.

In the router, I have a route requirement:

require(["yourmodule"], function(MyModule){ //... }) 
+6
source share
1 answer

This is a great guide to getting Married Backbone.js and Require.js:

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

+5
source

Source: https://habr.com/ru/post/904068/


All Articles