Chrome Packages app with JSRender and JSviews

185 Views Asked by At

Can I use JSRender and JSViews libraries(http://www.jsviews.com/) in building Chrome Packaged App? Does it violate the CSP policy?

This library syntax uses "script" tag to identify template definition in the HTML file...following is an example of it

<script id="theTmpl" type="text/x-jsrender"> <div>    <em>Name:</em>
{{:name}}    {{if showNickname && nickname}}
  (Goes by <em>{{:nickname}}</em>)    {{/if}} </div> </script>
1

There are 1 best solutions below

0
On

I don't believe JsRender and JsViews are currently CSP compliant, because template compilation uses new Function(). However pre-compilation should be very easy. See jsrender/issues/30 and jsrender/issues/164 . A precompile tool is planned for V1 or V1.1.

In fact you can already do your own precompiling simply by writing:

var myTemplate = $.templates("myTemplateMarkupString");

As to the script tag, no, you don't have to use that approach to declaring templates. As shown above, you can compile from strings or precompile. See http://www.jsviews.com/#compiletmpl for more details and examples.