🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
InstantPageLoader
This page was created by Hans.karlsen on 2025-09-23. Last edited by Wikiadmin on 2026-07-29.

You can pre-render and store ServerSide Blazor page HTML so that visitors receive cached page content without the normal ViewModel rendering and data fetch; use this for pages whose content can be served as static HTML.

How InstantPageLoader works

InstantPageLoader has two stages:

  1. Capture: Request a page with CACHETHIS. The application renders the page and posts its rendered page content to an unrooted ViewModel named SysCacheCapture.
  2. Serve from cache: Request the same page with FROMCACHE. The application obtains the stored HTML through an unrooted REST-enabled ViewModel named SysCacheGet and places that HTML below the main menu.

The cached content includes the page content and left-side area, but excludes the top menu. Because the cached response skips normal rendering and associated data retrieval, it can return much faster than a normally rendered page.

Before you use it

Use InstantPageLoader only when the rendered HTML is known ahead of time and can be reused. A suitable example is a public, mostly static information page where the same content can be served to every visitor.

Do not treat cached HTML as an interactive ViewModel page. The cache contains HTML, not the backing ViewModel state or its server-side behavior.

Requirement Purpose
An unrooted ViewModel named SysCacheCapture Receives captured HTML when you request CACHETHIS.
SysCacheCapture is REST allowed Allows the capture request to post to the ViewModel.
An unrooted REST-enabled ViewModel named SysCacheGet Finds the stored HTML when you request FROMCACHE.
Stored string values for rootid, viewmodel, and html Identifies the cached page and stores its rendered content.

Configure cache capture

Create the capture ViewModel in MDriven Designer's ViewModel Editor. The ViewModel must be named exactly SysCacheCapture, must be unrooted, and must be REST allowed.

  1. Create an unrooted ViewModel named SysCacheCapture.
  2. Enable REST access for the ViewModel.
  3. Add string columns named exactly:
    • rootid
    • viewmodel
    • html
  4. Implement the ViewModel logic so that it stores the incoming values in your data model.
  5. Decide whether the logic creates a new cache record or finds an existing record for the same rootid and viewmodel and replaces its html value.

For example, if your application has a page for root ID 42 in a ViewModel named ProductPage, the capture implementation can store one record identified by rootid = "42" and viewmodel = "ProductPage". A later capture for the same page can update that record with newly rendered HTML.

Capture a page

Request the ServerSide Blazor route with CACHETHIS as the final path segment:

/appli/ViewModel/rootid/CACHETHIS

Replace ViewModel and rootid with the ViewModel and root ID for the page you want to cache. For example:

/appli/ProductPage/42/CACHETHIS

The application renders the requested page and tries to post the result to SysCacheCapture. The captured html is page content including the left side, but not the top menu.

Capture the page again whenever the content represented by the cached page changes. If you retain multiple cache records, make the lookup consistent with the same root ID and ViewModel values used at capture time.

Configure cache retrieval

Create an unrooted, REST-enabled ViewModel named exactly SysCacheGet. Its responsibility is to locate the previously stored HTML for the requested root ID and ViewModel and return that HTML.

When FROMCACHE is used, the ServerSide Blazor application performs the following request:

httpClient.GetStringAsync($"{baseurl}/Rest/SysCacheGet/Get/$null$?vTheId={id}&vTheViewModel={name}")

Configure SysCacheGet so that its lookup uses the incoming vTheId and vTheViewModel values to find the corresponding stored cache entry and render its HTML. In the earlier example, the lookup receives the equivalent of root ID 42 and ViewModel ProductPage, then returns the stored html value for that combination.

Serve a cached page

After a cache entry exists, request the route with FROMCACHE as the final path segment:

/appli/ViewModel/rootid/FROMCACHE

For example:

/appli/ProductPage/42/FROMCACHE

The application retrieves the cached HTML through SysCacheGet and renders it below the main menu. It does not perform the normal ViewModel rendering and associated data fetch for the page.

Limits of cached HTML

Cached page content is static HTML. Plan the page content around the following limits:

  • ViewModel-specific image and blob links do not work. Use images addressed by URLs instead. For example, cache an <img> that points to a URL rather than an image link that depends on the current ViewModel.
  • Actions appear but do not work. An action can be rendered into the captured HTML, but the cached response has no backing logic for it. Do not cache pages that require users to run actions.
  • The top menu is not part of the cached HTML. The application renders the retrieved cache content under the main menu.
  • The cache is your responsibility. Your SysCacheCapture and SysCacheGet implementations determine how entries are created, updated, and found.

For a page that needs live data, interactive actions, or ViewModel-specific blobs, use normal page rendering instead of FROMCACHE.

Sample merge model

A merge-model sample is available in the MDrivenComponents repository under MDrivenMergeable\InstantPageLoader\. Use it to inspect an example of the required cache capture and retrieval pattern.

See also