JS template engine baidutemplate and arttemplate comparison and application

Source: Internet
Author: User

Recently do the project with the JS template engine rendering Html,js template engine is in the last year to do the project is learned, but has been no use, only stay in the understanding level, until the project was used, JS template engine with two baidutemplate and arttemplate.

Project at the beginning of the Baidutemplate engine, the project was published to the Internet, the discovery of large amounts of data, the loading speed is slow, on the other template to consider whether the engine can improve rendering efficiency, on-line search, comparison found Arttemplate a little better, in-depth understanding and learning, Two engine syntax a bit different, but the result is one to the following, specifically describes the use of two engines:

First, baidutemplate:http://tangram.baidu.com/baidutemplate/

Second, arttempate:https://github.com/aui/arttemplate

Performance Test http://cdc.tencent.com/?p=5723

650) this.width=650; "src=" Http://cdc.tencent.com/wp-content/uploads/2012/06/1.png "/>

Baidutemplate Code Introduction

<script type= "Text/javascript" >    var html;    var  bt = baidu.template;    $ (function  ()  {         $.ajax ({            type:   "GET",            url:  "/Json/ Analysis.js ",            datatype:  ' json ',             success: function  (data)  {                html &NBSP;=&NBSP;BT (' t:jtlm_analysis ', {                     list: data                 });                 document.getelementbyid (' jtlm_analysis ') .innerhtml = html;             }        });     });</script>


Template Customization

<script id= "T:jtlm_analysis"  type= "text/html" >    <% for (var  i=0;i< list.length;i++) {%>    <div class= "widget-box transparent  collapsed ">        <div class=" widget-header  Widget-header-flat ">            

Rendering results

650) this.width=650; "src=" Http://images.cnitblog.com/i/319015/201407/051930526376061.png "/>

Arttemplate Code Introduction

$.ajax ({            type:  "GET",             url:  "Json/homejsonfirst.js?r="  +  Math.random (),            datatype:  ' json ',             success: function  (data)  {                //tab   Toggle                 html  = template (' t:layout_2 ', {                     list: data. layout_2                });            &Nbsp;    document.getelementbyid (' layout_2 ') .innerhtml = html;                 //                 html = template (' T:layout_6 ' , {                     title: JLConsts.Group_Layout_6_Name,                     list: data. layout_6                });                  document.getElementById (' layout_6 ') .innerhtml = html;                 //Happy Moment                 html =  template (' t:layout_7 ', {                     title: JLConsts.Group_Layout_7_Name,                     list:  data. layout_7                });


arttemplate Templates

<script id= "T:layout_8"  type= "text/html" >    

Rendering results

650) this.width=650; "src=" Http://images.cnitblog.com/i/319015/201407/051941331054094.png "style=" margin:0px; padding:0px;border:0px; "/>

Basic Traversal Template

650) this.width=650; "src=" Http://images.cnitblog.com/i/319015/201407/051944066051523.png "style=" margin:0px; padding:0px;border:0px; "/>

Multilayer Traversal templates

650) this.width=650; "src=" Http://images.cnitblog.com/i/319015/201407/051944358717829.png "style=" margin:0px; padding:0px;border:0px; "/>

Simple if Else

650) this.width=650; "src=" Http://images.cnitblog.com/i/319015/201407/051945174494232.png "style=" margin:0px; padding:0px;border:0px; "/>

JSON construction Results

650) this.width=650; "src=" Http://images.cnitblog.com/i/319015/201407/051944533713843.png "style=" margin:0px; padding:0px;border:0px; "/>

By contrast, arttemplate renders faster, and for infrequently updated data, we can generate JSON on a timed basis and render through the Arttemplate engine, which can greatly improve the speed of website access.

Case Appreciation



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.