• Stars
    star
    128
  • Rank 281,044 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 6 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Accelerated server-side rendering.

License: MIT npm version Build Status

@bitovi/velocirender

Accelerated server-side rendering.

Install

Install from npm:

npm install @bitovi/velocirender

Or Yarn:

yarn add @bitovi/velocirender

Getting Started

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

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

node_modules/.bin/velocirender 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

Velocirender comes with CLI and JavaScript APIs.

CLI

The command-line interface is the easiest way to use Velocirender. 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/velocirender build/index.html

Remote

node_modules/.bin/velocirender 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.
  • --key: An SSL key. This should match what is provided to Node https.
  • --cert: The SSL certificate. This should match what is provided to Node https.
  • --no-cache-html: By default Velocirender caches the HTML skeleton (everything that occurs before API requests are made). For the vast majority of apps this is fine, but if you do something weird like write a Math.random() into your output you might need this (file an issue to discuss first, you almost definitely don't need it).

Cache considerations

When running from a remote HTTP(S) address, Velocirender 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 Velocirender 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

Velocirender 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 velocirender = require('@bitovi/velocirender');
const { ReactDOM, App } = require('./dist/webpack-build-whatever.js');

const handler = velocirender(({ 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 velocirender = require('@bitovi/velocirender');
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(velocirender(({ 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 Velocirender will handle those routes.

Callback argument

Velocirender 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 Velocirender 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.

velocirender.serve()

A second API works like the CLI. Give it a path or URL and options that match the CLI's options. It will create a server for the app.

const velocirender = require('@bitovi/velocirender');

const server = velocirender.serve('https://bitovi.github.io/dog-things-react/', {
  port: 8089
});

The second argument options should match the available CLI flags.

Browser Compatibility

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

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

In browsers that don't support these technology Velocirender 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

More Repositories

1

jquerypp

jQuery's missing utils and special events
JavaScript
1,220
star
2

react-to-web-component

Convert react components to native Web Components. Works with Preact too!
TypeScript
688
star
3

documentjs

The sophisticated documentation engine
JavaScript
599
star
4

funcunit

A functional test suite based on jQuery
JavaScript
570
star
5

syn

Standalone Synthetic Event Library
JavaScript
444
star
6

checklist

A JavaScript Project Checklist
JavaScript
146
star
7

testee

Automated cross-browser JavaScript testing made easy
JavaScript
119
star
8

documentcss

A documentation/guide portal for the Live Style Guide feature of DocumentJS
HTML
72
star
9

hatchify

JavaScript, open source, CRUD app scaffolding that turns schemas into an app quickly, while allowing customization later.
TypeScript
71
star
10

github-actions-deploy-docker-to-ec2

GitHub Action to deploy any docker-composed app to an AWS EC2 VM.
59
star
11

launchpad

NodeJS Browser Launcher
JavaScript
45
star
12

ylem

Add Observable View-Models to React components
JavaScript
42
star
13

bitops

Automate the provisioning and configuration of cloud infrastructure with BitOps docker image
Python
34
star
14

canui

CanJS and jQuerypp
JavaScript
28
star
15

use-simple-reducer

A react state mechanic that supports simple asynchronous reducer functions
TypeScript
27
star
16

github-actions-react-to-github-pages

GitHub Action for hosting a React app on GitHub Pages
22
star
17

training

Bitovi's training material
JavaScript
19
star
18

github-actions-deploy-eks-helm

Shell
19
star
19

canjs.com

The CanJS homepage and distributable files
JavaScript
17
star
20

mutationobserver

JavaScript
15
star
21

academy

Everything we know about frontend, backend, UX, and Devops consulting and management.
TypeScript
14
star
22

landscaper

Apply code mods to projects, awesomely
JavaScript
14
star
23

optimizely-as-code

optimizely-as-code
JavaScript
12
star
24

github-actions-aws-secrets-manager

TypeScript
11
star
25

miner

Localhost tunnelling service wrappers
JavaScript
11
star
26

github-actions-storybook-to-github-pages

Deploy a Storybook build to GitHub Pages
9
star
27

github-actions-deploy-static-site-to-aws

HCL
9
star
28

querystring-parser

JavaScript
8
star
29

github-actions-docker-publish

8
star
30

eslint-config

JavaScript
8
star
31

github-actions-deploy-stackstorm

GitHub Action to deploy StackStorm to AWS (βeta)
Shell
8
star
32

fluid-text

Tailwind utility class plugin for sizing text smoothly between your breakpoints.
JavaScript
8
star
33

universal.js

Universal library wrappers
JavaScript
7
star
34

stateful-mocks

TypeScript
7
star
35

crawlify

JavaScript
6
star
36

github-actions-deploy-prometheus

Deploy a prometheus and configure it to monitor things
5
star
37

sequelize-create-with-associations

TypeScript
5
star
38

github-actions-docker-to-azure-vm

Stand up an Azure VM and run your Docker Compose on it.
Shell
5
star
39

eslint-plugin

TypeScript
4
star
40

cordovaboilerplate

A starter app for Cordova projects
JavaScript
4
star
41

bootdocs

Bootstrap documentation generated with DocumentJS
CSS
4
star
42

slack-bot-gptchat

App to manage a gpt chat bot server
Python
4
star
43

github-actions-gcp-bucket

Shell
3
star
44

eslint-plugin-nx-glue

Allows local ESLint Rules written in TypeScript to be available within a Nx workspace or any project
TypeScript
3
star
45

test-saucelabs

Runs test pages on Saucelabs
JavaScript
3
star
46

statistical-software-estimator

A statistical estimator for software projects.
JavaScript
3
star
47

opensource-analytics-dashboard

TypeScript
3
star
48

engine-dependencies

Install npm dependencies based on what version of Node you are using
JavaScript
3
star
49

web-locks-polyfill

A polyfill for the web-locks api
JavaScript
3
star
50

jira-auto-scheduler

A JIRA auto-scheduling application for product management.
JavaScript
3
star
51

github-actions-commons

Common things for GitHub Actions
HCL
3
star
52

shadow

Shadow-DOM for everyone
JavaScript
3
star
53

cqrs-example

TypeScript
3
star
54

signalr-chat

JavaScript
3
star
55

github-actions-deploy-docker-to-gcp

Deploy an app or service to GCP Compute Engine
Shell
3
star
56

dog-things-react

A React version of the Dog Things app with Velocirender
JavaScript
3
star
57

github-actions-deploy-aws-ecr-registry

Repo to deploy an AWS ECR Registry
2
star
58

calendar-events-component

Show events from a google calendar
HTML
2
star
59

signalr-hub

JavaScript
2
star
60

app-staffing

TypeScript
2
star
61

grunt-testee

Grunt task for Testee
JavaScript
2
star
62

vintage-shop

An example app for learning style guide driven development
CSS
2
star
63

devops-training-ec2-gha-example

Example repo to deploy an app to an EC2 instance with a GitHub Action
2
star
64

fast-react-static-renderer

Fast react static render framework
2
star
65

nx-cucumber-plugin

TypeScript
2
star
66

bithub-embed

Embed code for Bithub.com
CSS
2
star
67

github-actions-deploy-github-runner-to-ec2

Deploys a GitHub runner to an EC2 instance
Shell
2
star
68

github-actions-deploy-rds

Deploys an AWS RDS Database instance
2
star
69

testee-client

Testee client adapters for QUnit, Jasmine and Mocha
JavaScript
1
star
70

operations-example-deno-ec2

deploy a simple deno app to EC2
Dockerfile
1
star
71

github-actions-npm-publish

Github Action for NPM Publish
1
star
72

github-actions-deploy-ecs

1
star
73

github-actions-deploy-eks

github action to deploy AWS eks cluster
1
star
74

bitops-operations-repo-generator

JavaScript
1
star
75

github-actions-apply-sql-files-to-postgres

Iterate through .sql files inside a folder using psql to initialize a database
1
star
76

steal.js

JavaScript
1
star
77

dog-things-vue

Example app of using Velocirender in a Vue app
Vue
1
star
78

jmvc-generators

Generators for JavaScriptMVC
HTML
1
star
79

bitovi-tools

Tasks for building Bitovi projects(eg: CanJS, jQuery++)
JavaScript
1
star
80

book

Book
JavaScript
1
star
81

steal-build

StealJS and build tools for NodeJS
JavaScript
1
star
82

n8n-getting-started

Bitovi's getting started guide for N8N
Dockerfile
1
star
83

learn-typescript

Learn TypeScript with small examples
TypeScript
1
star
84

devops-streaming-examples

Examples for Bitovi DevOps Streaming
JavaScript
1
star
85

snapshot-test

Visual snapshot testing in the browser for any test framework.
JavaScript
1
star
86

temporal-publish-sample

TypeScript
1
star
87

scrolling-nav

JavaScript
1
star
88

bitscaffold

TypeScript
1
star
89

voice-guided-interview

Example app using voice to fill out an interview.
JavaScript
1
star
90

github-actions-deploy-kubernetes

GitHub Action to deploy Kubernetes
1
star
91

github-actions-deploy-aurora

GitHub action to deploy an Aurora DB Instance
1
star
92

github-actions-docker-ecr-publish

1
star
93

github-actions-deploy-redis-db

Deploys a Redis database cluster group. From one to multiple nodes.
1
star