Skip to content

Page now, slow parts later

Most sites load the slow parts of a page with a script and an API route for each part. In Novis, the page and its slow parts come in one request, and you write no script. Core\Html::later runs a slow part of a page. Core\Response::sendSlotted() sends the page before that part is done. Press play to see each step.

Home
example.com
Welcome back
Loading posts…3 new blog posts
Loading deals…2 deals in the shop
NetworkName0 requests
home.nvsapi/posts.nvsapi/deals.nvshome.js
1<?nvs
2Account::check();
3echo html`<h1>Welcome back</h1>
4<div id="posts">Loading posts…</div>
5<div id="deals">Loading deals…</div>
6<script src="/home.js"></script>`;
1<?nvs
2Account::check();
3echo Blog::latestPosts();
1<?nvs
2Account::check();
3echo Shop::deals();
1for (const id of ['posts', 'deals']) {
2 fetch(`/api/${id}`)
3 .then((response) => response.text())
4 .then((html) => {
5 document.getElementById(id).innerHTML = html;
6 });
7}
1<?nvs
2Account::check();
3Core\Response::sendSlotted();
4var $posts = Core\Html::later(
5 fn() => Blog::latestPosts(),
6 { placeholder: html`<p>Loading posts…</p>` },
7);
8var $deals = Core\Html::later(
9 fn() => Shop::deals(),
10 { placeholder: html`<p>Loading deals…</p>` },
11);
12echo html`<h1>Welcome back</h1>{$posts}{$deals}`;
nvs serve
Blog::latestPosts()