So far, our users#show
action pulls down both a User
model and a Repos
collection for that model. If we were to navigate from users#index
to users#show
, we already have that user model cached in memory (because we fetched it in order to render the list), but we have to make a roundtrip to the server to fetch the Repos
, which aren't part of the User
attributes. This means that instead of immediately rendering the users/show
view, we wait for the Repos
API call to finish. But what if instead we want to lazy-load the Repos
so we can render that view immediately for a better user experience?
We can achieve this by lazy-loading models or collections in our subviews. Check out the users#show_lazy
action, which demonstrates this approach:
// app/controllers/users_controller.js
module.exports = {
// ...