Alex Rivera | Logout

JavaScript template library that doesn't use eval/new Function

Asked 2012-05-24T20:24:43.873
13

Google Chrome extensions using manifest_version: 2 are restricted from using eval or new Function. All of the JavaScript templating libraries I checked (mustachejs, underscorejs, jQuery template, hoganjs, etc) use new Function. Are there any that are fairly mature and supported that don't use either?

Info about the security restrictions.

Edit
Report

3 Answers

2

Closure Templates is a templating library that does not use eval. Templates are compiled to JavaScript ahead of time, so that what gets included in your app is a plain .js file that should not run into CSP issues.

answered 2012-05-25T01:00:02.210
2

Distal template doesn't use eval.

answered 2012-07-11T05:33:12.757
0

Maybe you can write a function eval1:

function eval1(blah) {
    var s = document.createElement("script");
    s.src = blah;
    document.head.appendChild(s);
    document.head.removeChild(s);
}

and do a find/replace in the library you want, but that'd be cheating, right?

answered 2012-05-28T04:32:41.910

Your Answer