write-html

0.1.2 • Public • Published

write-html

build status dependency status

Write HTML in parts, <head> first, <body> later

Example

WriteHtml encourages you to write the <head> of your html page immediately and write the body once you have done some async things. this allows script tags, style tags & assets like link prefetching to load in parallel with your database fetching code.

var http = require("http")
var WriteHtml = require("write-html")

var server = http.createServer(function (req, res) {
    if (req.url.match(/\/user\//)) {
        var userParts = req.url.split("/")
        var userId = userParts[userParts.length - 1]

        var writer = WriteHtml(req, res)
        writer.writeHead("<head><title>User page</title></head>")

        db.get("user:" + userId, function (err, user) {
            writer.writeBody("<body>" + render(user) + "</body>")
        })
    }
})

Installation

npm install write-html

Contributors

  • Raynos

MIT Licenced

Readme

Keywords

none

Package Sidebar

Install

npm i write-html

Weekly Downloads

0

Version

0.1.2

License

none

Last publish

Collaborators

  • raynos