write-html

Write HTML in parts, first, later

write-html

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

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 (reqres) {
    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 (erruser) {
            writer.writeBody("<body>" + render(user) + "</body>")
        })
    }
})

npm install write-html

  • Raynos