Extension for nun for static content versioning
Switch branches/tags
Nothing to show
Latest commit 80d39ec Oct 29, 2010 @akaspin Remove sys from readme
Failed to load latest commit information.



nun-v is extension for nun templating engine for static content versioning inspired with tornado static files and aggressive file caching.

How it works?

For example, you can add following settings in nginx.conf:

location /static/ {
    root /var/www/static;
        if ($query_string) {
        expires max;

And if the link takes the following form:


... browser will use a locally cached copy without ever checking for updates on the server.


nun-v provides asynchronous compile-phase filter for rarely changing files.


<h1>Static image</h1>
<img src="{{~v}}title.jpg{{/v}}" />


var nun = require('nun');
var nunV = require('nun-v');

var filters = {
    v: nunV.filter(__dirname + "/static", "/static"),

var origin = __dirname + "/template.html";

nun.render(origin, {}, {filters:filters}, function(err, output){
    if (err) throw err;
    var buffer = '';
    output.addListener('data', function(data){ buffer += data; })
          .addListener('end', function(){ console.log(buffer) });


<h1>Static image</h1>
<img src="/title.jpg?v=123456" />

... and

Since the v argument is based on the content of the file, if you update a file and restart your server, it will start sending a new v value, so the user's browser will automatically fetch the new file. If the file's contents don't change, the browser will continue to use a locally cached copy without ever checking for updates on the server, significantly improving rendering performance.