jade-static-cache
jade-static-cache
is Express middleware combined with a Jade filter that can be used to
easily apply far future cache-control headers to your static files. When a file is modified,
its URL will be modified, forcing the browser to refetch the file.
Installation
$ npm install jade-static-cache
How to Use
This module currently supports Express 3.
var express = ;var path = ;var jadeStaticCache = ;var app = ; var staticDir = path; app; app; app;app;app;app;
static
takes two parameters: The first is the root directory where your static
files are located. The second is the URL path that will be used to serve your static
files. By default, jade-static-cache runs in production mode. Running in dev mode can
be achieved by passing in true
as an optional third parameter.
In your Jade template
:staticCache link(rel='stylesheet', href='/css/main.css') script(src='/scripts/base.js')
In production mode, this will render
In dev mode, this will render:
In both cases, the response will be sent to the browser along with a cache-control header that has a max-age value of 1 year. This will prevent the browser from making future requests for the file.
If the file is modified in the future, the production URL will also be modified. Note that you will need to restart your server for this to take effect.