How to compile dust js server side rendering for IE7

1.3k Views Asked by At

I have an application which uses a lot of dust templates. IE8+ and other modern browsers such as Chrome there are no issues with client-side rendering but in IE7 and below this does not work properly.

Is there a way to run the dust.js in the server and return a compiled template?

2

There are 2 best solutions below

0
On

You can do this with Node.JS...

npm install dustjs-linkedin - (personally use the LinkedIn fork of dust)

var http = require('http');
var dust = require('dustjs-linkedin');

http.createServer(function (req, res) {
    var compiled = dust.compile('<h1>Hello {name}</h1>', 'mytemplate');
    res.end(compiled);
}).listen(80);

Obviously this is just an example, in a real script you would probably use some other mechanism, maybe Express. You would also use the 'fs' module to load the template from file.

On the client side request the compiled script from the server, your template will automatically be registered, so you can just do:

dust.render('mytemplate', {name : 'World'}, function(err, str){
    ...
});
0
On

You can use duster.js to watch and precompile templates on the server.

This blog post (from the author) explains how this would work.

Update: If you use NodeJs Tools for Visual Studio for development, then you can use this extension.

I published a Visual Studio extension that automatically generates the precompiled templates on server, as soon as you save the files. All you have to do is include the generated .js file in your page. Checkout DustJs Compiled Template Generator.

Usage is explained in here with screenshots.