Question

Does Durandal load the ViewModels/View during initial load/upfront or load them on demand.

Say i have a very huge website with 100 or more pages/View and each view has a pretty big viewModel. will Durandal Load all of them upfront ?

How about the Data Calls in each view, will all those be triggered if it is loading them upfront ?

Trying to understand the Behavior of Durandal

Was it helpful?

Solution

Durandal loads views and viewmodels as needed (on demand). So in your example, with 100 views and viewmodels, you would only be loadin gthe ones you use. Watch the Network tab of your browser tools and you can see them come across as required.

Also, once they are local, they are cached in the browser, which is a good thing.

If your viewmodel's make data calls on "activate" then yes, they will be called each time you activate them. See the Durandal docs for more about the lifecycle events.

However, if you run the optimizer.exe, it will package up all of them and bring them to the client in a single shot (minified) up front. This is not something I do during development. But, if you want to load everything up front after you go live, this is a way to get the whole app local.

For your app with 100+ views, I'd probably load as I go since it is unlikely that anyone will hit all 100 views in a single usage (I am guessing). It depends on how you intend the app to be used.

OTHER TIPS

I am new to durandal but I am fairly sure that you have two options for this.

You can load them on demand which is the default or you can build it as an app which will minify all your app files into a single package. Not sure about the specifics of that build step, but presumably if you go that approach then your entire app gets downloaded in one shot.

As for the data calls in each view, you would normally kick those off in the activate function of your view model. So they will only ever happen when your view models get activated and not altogether up front.

So for your scenario Durandal would work quite nicely.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top