raptor-data-providers module provides support for the more efficient and simpler "Pull Model "approach to providing templates with view model data.
- Push Model: Request all needed data upfront and wait for all of the data to be received before building the view model and then rendering the template.
- Pull Model: Register data providers and immediately start rendering the template. Let the template pull the data needed during rendering.
The Pull Model approach to template rendering requires the use of a templating engine that supports asynchronous template rendering (e.g. raptor-templates and dust). This is because before rendering the template begins not all of data may have been fully retrieved. Parts of a template that depend on data that is not yet available are rendered asynchronously with the Pull Model approach.
Push Model versus Pull Model
The problem with the traditional Push Model approach is that template rendering is delayed until all data has been fully received. This reduces the time to first byte, and it also may result in the server sitting idle while waiting for data to be loaded from remote services. In addition, if certain data is no longer needed by a template then only the template needs to be modified and not the controller.
With the new Pull Model approach, template rendering begins immediately. In addition, fragments of the template that depend on data from data providers are rendered asynchronously and wait only on the associated data provider to complete. The template rendering will only be delayed for data that the template actually needs.
Register data providers upfront: