Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/468.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 优化脚本模板_Javascript_Jquery_Templates_Jquery Mobile_Mustache - Fatal编程技术网

Javascript 优化脚本模板

Javascript 优化脚本模板,javascript,jquery,templates,jquery-mobile,mustache,Javascript,Jquery,Templates,Jquery Mobile,Mustache,我使用脚本模板在javascript中创建可恢复的html标记。模板使用mustache将标记替换为正确的值。然后jquerymobile会呈现并再次呈现html。代码段如下所示: <!doctype html> <html> <head> <meta charset="UTF-8" /> <title>

我使用脚本模板在javascript中创建可恢复的html标记。模板使用mustache将标记替换为正确的值。然后jquerymobile会呈现并再次呈现html。代码段如下所示:

<!doctype html>
            <html>
                <head>
                    <meta charset="UTF-8" />
                    <title>jQuery Mobile</title>
                    <meta name="viewport" content="width=device-width, initial-scale=1"> 
                    <meta charset="utf-8" http-equiv="X-UA-Compatible" content="IE=9" />



                </head>
                <body>
                    <!-- Page Templates -->

<script id="page_header_tpl" type="text/template">
<div data-role="header" class="toolbar {{#class}}{{{class}}}{{/class}}" {{#id}}id="{{{id}}}" {{/id}}>
<h1>{{{title}}}</h1>
<div data-role="ui-bar" class="ui-bar" id="ui-top">
{{#buttons}}
        {{{.}}}
{{/buttons}}
</div><!-- /navbar -->

{{#navbar}}
    {{{navbar}}}
{{/navbar}}
</div>
</script>
<script type="text/javascript">
//Function for creating the header
function createPageHeader(data) {
      html = $('#page_header_tpl').html();
    return Mustache.render(html, data);
}
 //Calling the function
 var header = createPageHeader({ class : 'aheader', id : 'my id',  title : 'Page 1'});
<script>
</body>
</html>

jquerymobile
{{{title}}}
{{{#按钮}
{{{.}}}
{{/按钮}
{{{#navbar}
{{{navbar}}}
{{/navbar}}
//用于创建标题的函数
函数createPageHeader(数据){
html=$('#页眉_tpl').html();
返回Mustache.render(html,数据);
}
//调用函数
var header=createPageHeader({class:'aheader',id:'my id',title:'Page 1'});

我的问题是,我可以使用什么样的技术来优化模板元素的调用和放置到html文件中?元素的快速检索?通过胡须更快地解析?记忆技术?etc

您的最佳选择可能是在客户机上使用。它与小胡子完全兼容,并提供了一种实现更好性能的方法

它还添加了一堆额外的助手,但如果您希望使模板与胡须完全兼容(例如在服务器端使用),则不必使用这些助手

不仅如此,它还可用于编译模板

以下是一篇比较文章,其中有一些更有用的链接: