npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@bitovi/incremental

v1.0.2

Published

Incremental rendering - Boot your SPA faster

Downloads

8

Readme

License: MIT npm version Build Status

@bitovi/incremental

Accelerated server-side rendering.

Install

Install from npm:

npm install @bitovi/incremental

Or Yarn:

yarn add @bitovi/incremental

Getting Started

The Getting Started guide goes over everything in much more depth but here is a primer.

Once you've installed incremental you can use the CLI to start a server and point at an HTTP(S) endpoint like so:

node_modules/.bin/incremental https://bitovi.github.io/dog-things-react/

This will tell you to visit http://localhost:8080 where you see the sight load incrementally. Continue on with the guide which walks you through what is happening and how to integrate this into your workflow.

Usage

incremental comes with CLI and JavaScript APIs.

CLI

The command-line interface is the easiest way to use incremental. Provide a path to your production HTML file and a few options, if needed. The HTML file can be a local path or a remote HTTP(S) address:

Locally

node_modules/.bin/incremental build/index.html

Remote

node_modules/.bin/incremental https://bitovi.github.io/dog-things-react/

Flags

The following CLI flags are available for use:

  • --port: Specify the port to use, otherwise 8080 will be used.

Cache considerations

When running from a remote HTTP(S) address, incremental will download static assets and serve them from a local cache. That cache will be used until the next time the server starts, at which time they'll be re-downloaded.

This means that a deployed incremental server doesn't need to be redeployed when you release a new version of your front-end app; but you will need to restart the server.

See this issue for discussion on more advanced caching coming in the future.

JavaScript API

incremental takes a function that is given a rendering context. This includes a document, the request and response objects. A function is returned with a signature of (request, response) and can be used as Express middleware, directly with require('http'), etc.

Here's an example that uses http module directly:

const incremental = require('@bitovi/incremental');
const { ReactDOM, App } = require('./dist/webpack-build-whatever.js');

const handler = incremental(({ document, request }) => {
  let root = document.createElement('div');
  root.setAttribute("id", "root");
  document.body.appendChild(root);
  ReactDOM.render(React.createComponent(App), root);
});

require('http').createServer(handler).listen(8080);

Note the above doesn't handle serving static assets. If you are using the http module directly you probably already know how to handle this, but most will likely want to use a framework like Express. Here's an example that does so:

const incremental = require('@bitovi/incremental');
const { ReactDOM, App } = require('./dist/webpack-build-whatever.js');
const express = require('express');
const app = express();

// Add any normal Express middlware you use here.
app.use(express.static(__dirname + '/build', { index: false }));

// Add this last.
app.use(incremental(({ document, request }) => {
  let root = document.createElement('div');
  root.setAttribute("id", "root");
  document.body.appendChild(root);
  ReactDOM.render(React.createElement(App), root);
}));

app.listen(8080);

Note that { index: false } is provided to express.static. This disables serving the index.html file for routes like /. This is disabled in this example because incremental will handle those routes.

Callback argument

incremental takes a handler function as its only argument. That function receives a context object that contains the following properties:

  • request: The request object from the HTTP request.
  • response: The response object from the request. Note that can set headers on this response, but you won't want to call .write() or .end() as incremental calls those itself.
  • document: A document that is scoped to this request. You can modify this document just as you would in a browser. Typically you'll want to create a root element to render your application onto. This document is backed by jsdom.
  • window: A window object. This contains many (but not all) of the properties that are seen in a browser window.

Browser Compatibility

incremental utilizes recent additions to the browser specs such as preload, fetch, and ReadableStream.

As of today incremental rendering is possible in Chrome and Safari >=12.

In browsers that don't support these technology incremental will fallback to the traditional SSR method of waiting for a fully rendered page. We call these separate strategies:

  • incremental strategy is for modern browsers with streaming capabilities.
  • legacy strategy is for older browsers.

Changelog

See the latest releases on GitHub.

License

MIT