Giter Site home page Giter Site logo

pelo's Introduction

pelo

Lightning fast server-side rendering with tagged template literals

A tiny library that enables lightning fast server-side rendering with hyperx-like libraries such as bel, yo-yo and choo/html. It replaces the tag function of those libraries and just renders string without creating intermediate objects.

Installing

npm install pelo

Usage

ssr.js: Call pelo.replace(moduleId) before you require any view module, bel in this case.

const pelo = require('pelo')
pelo.replace('bel')
const view = require('./view')

const renderedString = view('pelo').toString()

view.js: You don't need to change your view files at all. You can use them for client-side rendering and server-side rendering.

const html = require('bel')

module.exports = function helloView(name) {
  return html`<p>Hello, ${name}</p>`
}

Benchmark

Rendering a simple view 10,000 times:

node benchmark.js
tag time (ms)
pelo 219.093
bel 1982.610

Motivation

Server-side rendering with modern JavaScript frameworks is slow. In general, they focus on the client-side, and generate virtual/real DOMs for efficient DOM updates from templates. However, this approach is a bit overkill when we focus on server-side rendering. Because the templates already look like HTML, it should be faster if they directly render HTML strings without creating intermediate object representations.

With bel, we can write HTML with tagged template literals and use them to create declarative views on browser. If we can use the same template also for directly generating HTML string on server-side, it will be a huge win.

Thanks

Thanks @yoshuawuyts for lots of advice!

pelo's People

Contributors

goto-bus-stop avatar majgis avatar shuhei avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.