Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including express-template-cache with all npm packages installed. Try it out:

var expressTemplateCache = require("express-template-cache")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

express-template-cache v0.1.0

Adds cached rendering of templates to Express.

Express Template Cache

express-template-cache is a simple and lightweight module that adds cached rendering of templates to Express. It is useful for serving static pages that only need to be rendered once.

The first time a particular template is requested, it is rendered and the result is cached to memory. Subsequent requests will simply be served from the cache, instead of rendering the template again. This eliminates the need to manually render templates for static pages, while keeping page load times to a minimum.

Installation

npm:

$ npm install express-template-cache

Usage

To use this module, just require('express-template-cache'), and it will monkey-patch Express, adding the res.renderStatic() method. It is used in the exact same way as res.render(), however it implements the caching strategy described above.

require('express-static-render');

app.get('/', function(req, res) {
    res.renderStatic('index', { title: 'My Awesome Website' });
});

Planned Features

  • HTTP Cache-Control and conditional GET support
  • Way to define unique views to be rendered other than just by name
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free