这是编写dustjs模板以加快渲染速度的一些技巧吗?node.js
我使用这是编写dustjs模板以加快渲染速度的一些技巧吗?node.js,node.js,render,dust.js,Node.js,Render,Dust.js,我使用dustjs来呈现我的邮件内容,我发现呈现一些更大的模板时速度很慢。在编写dustjs模板以提高渲染速度时,有什么提示吗?还是一些好的做法 详情: 我的模板由几个组件(超过5个)组成,每个组件如果与其他组件不同,则有一个组件示例,如下所示: <tr> <td align="center" valign="top" bgcolor="#FFFFFF"> <table cellpadding="0" cellspacing="0" width="650
dustjs
来呈现我的邮件内容,我发现呈现一些更大的模板时速度很慢。在编写dustjs
模板以提高渲染速度时,有什么提示吗?还是一些好的做法
详情:
我的模板由几个组件(超过5个)组成,每个组件如果与其他组件不同,则有一个组件示例,如下所示:
<tr>
<td align="center" valign="top" bgcolor="#FFFFFF">
<table cellpadding="0" cellspacing="0" width="650">
<tr>
<td align="center">
<table width="590" border="0" cellspacing="0" cellpadding="0">
{@eq key=haveBanner value=1}
<tr>
<td height="105" align="center" valign="middle">
<a href="{edm_monitor_server}/api/clickRecord?{.|sellerPage}&{trackCodeData|gaTrackCode|dbTrackCode|entityId|entityType|edmpid|recId|userId|token|final}" target="_blank"><img src="{bannerUrl|pictureUrl}" width="590" border="0"></a>
</td>
</tr>
{:else}
<tr>
<td align="center">
<table cellpadding="0" cellspacing="0" width="590" height="75" style="border-top:solid 3px #343434">
<tr>
<td width="130" align="left" valign="middle">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left" height="55">
<a href="{edm_monitor_server}/api/clickRecord?{.|sellerPage}&{trackCodeData|gaTrackCode|dbTrackCode|entityId|entityType|edmpid|recId|userId|token|final}" target="_blank"><img src="{sellerLogo|pictureUrl}" width="110" height="55"></a>
</td>
</tr>
</table>
</td>
<td width="460" align="left">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left"><a href="{edm_monitor_server}/api/clickRecord?{.|sellerPage}&{trackCodeData|gaTrackCode|dbTrackCode|entityId|entityType|edmpid|recId|userId|token|final}" target="_blank" style="text-decoration:none"><font style="font-family:arial;font-size:16px;color:#292929">{compName}</strong></a></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
{/eq}
<tr>
<td>
<table border="0" cellpadding="0" cellspacing="0" style="border:solid 1px #dbdbdb" width="594">
<tr>
<td width="149" valign="top" style="border-right:solid 1px #dbdbdb">
<table width="146" cellspacing="0" cellpadding="0">
<tr>
{@eq key=selectedProductFlag value=1}
<td height="80" style="padding:20px 20px"><a href="{edm_monitor_server}/api/clickRecord?{.|sellerPromoteProdListPage}&{trackCodeData|gaTrackCode|dbTrackCode|entityId|entityType|edmpid|recId|userId|token|final}" target="_blank" style="text-decoration:none"><font style="font-family:arial;font-size:18px;color:#333333"><b>Promotion Products</b></font></a></td>
{:else}
<td height="80" style="padding:20px 20px"><a href="{edm_monitor_server}/api/clickRecord?{.|sellerProdListPage}&{trackCodeData|gaTrackCode|dbTrackCode|entityId|entityType|edmpid|recId|userId|token|final}" target="_blank" style="text-decoration:none"><font style="font-family:arial;font-size:18px;color:#333333"><b>Promotion Products</b></font></a></td>
{/eq}
</tr>
<tr>
<td align="center" height="26" valign="top">
<table width="119" border="0" cellspacing="0" cellpadding="0">
<tr>
<td style="border-top:solid 1px #e5e5e5"><img src="http://newimg.globalmarket.com/PA/edm/images/spacer.gif" height="1" width="1"></td>
</tr>
</table>
</td>
</tr>
{#finalProdGroupList}
<tr>
<td height="35" valign="top">
<table width="146" cellspacing="0" cellpadding="0">
<tr>
<td style="padding-left:25px"><a href="{edm_monitor_server}/api/clickRecord?{.|sellerGroupProdListPage}&{trackCodeData|gaTrackCode|dbTrackCode|entityId|entityType|edmpid|recId|userId|token|final}" target="_blank" style="text-decoration:none"><font style="font-family:arial;font-size:12px;color:#484848">{prodGroupName}</font></a></td>
</tr>
</table>
</td>
</tr>
{/finalProdGroupList}
</table>
</td>
<td width="443" valign="top">
<table width="442" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<table width="442" border="0" cellspacing="0" cellpadding="0" height="255">
<tr>
{#secondaryProducts}
{#productList spIdx=$idx}
{@eq key=$idx value=2}
<td align="center" valign="top" width="147">
{:else}
<td align="center" valign="top" style="border-right:solid 1px #dbdbdb" width="147">
{/eq}
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="146" align="center">
<a href="{edm_monitor_server}/api/clickRecord?{.|sellerProductPage}&{trackCodeData|gaTrackCode|dbTrackCode|entityId|entityType|edmpid|recId|userId|token|final}" target="_blank"><img src="{photoUrl|pictureUrl}" border="0" width="126" height="126" alt="{fullProdName}"></a>
</td>
</tr>
<tr>
<td align="center">
<table width="126" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center">
<table cellpadding="0" cellspacing="0" width="126">
<tr>
<td align="left" height="33" valign="top" style="line-height:15px">
<a href="{edm_monitor_server}/api/clickRecord?{.|sellerProductPage}&{trackCodeData|gaTrackCode|dbTrackCode|entityId|entityType|edmpid|recId|userId|token|final}" target="_blank" style="text-decoration:none"><font style="font-family:Arial;font-size:12px;color:#333333">{productName}</font></a>
</td>
</tr>
<tr>
<td align="left" height="20" valign="middle"><font style="font-family:Arial;font-size:12px;color:#999999">{certification}</font></td>
</tr>
<tr>
{@eq key=payForInqFlag value=1}
<td align="left" height="35" valign="middle"><a href="{edm_monitor_server}/api/clickRecord?{.|addInquiryPage}&{trackCodeData|gaTrackCode|dbTrackCode|entityId|entityType|taskId|edmpid|recId|userId|token|final}" title="Get Latest Price" style="color: #555555; text-decoration: none;" target="_blank"><img src="http://newimg.globalmarket.com/PA/edm/images/getprice2.png" width="128" height="25"></a></td>
{:else}
<td align="left" height="35" valign="middle"><a href="{edm_monitor_server}/api/clickRecord?{.|m2bProductPage}&type=getPrice&{trackCodeData|gaTrackCode|dbTrackCode|entityId|entityType|taskId|edmpid|recId|userId|token|final}" title="Get Latest Price" style="color: #555555; text-decoration: none;" target="_blank"><img src="http://newimg.globalmarket.com/PA/edm/images/getprice2.png" width="128" height="25"></a></td>
{/eq}
</tr>
<tr>
<td height="7"></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
{/productList}
{/secondaryProducts}
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
{@eq key=haveBanner value=1}
{:else}
{/eq}
{@eq key=selectedProductFlag值=1}
{:else}
{/eq}
{#finalProdGroupList}
{/finalProdGroupList}
{#二次产品}
{#productList spIdx=$idx}
{@eq key=$idx value=2}
{:else}
{/eq}
{认证}
{@eq key=payForInqFlag值=1}
{:else}
{/eq}
{/productList}
{/二次产品}
您的问题很可能是使用了大量的滤尘器
例如:
&{trackCodeData|gaTrackCode|dbTrackCode|entityId|entityType|edmpid|recId|userId|token|final}
其中一些过滤器甚至在循环中运行。看起来您在该模板的每个渲染中运行了100多个过滤器。过滤器是同步和串行执行的,因此在过滤器完成之前,Dust无法继续渲染模板
如果不知道这些过滤器的作用,就很难对过滤器本身提出具体的建议。但是,您似乎多次使用相同的过滤器来输出相同的数据。如果可能,您应该预生成此数据并将其添加到上下文中,而不是动态生成它
如果禁用了空格压缩,则可以通过启用空格压缩获得更多的循环:
dust.config.whitespace = false;
但是灰尘本身是很快的。如果没有你的过滤器,你的模板会在3毫秒左右呈现给我。这个问题不适合堆栈溢出的格式。你能分享一个慢的模板吗?我尝试了没有过滤器的测试模板,它的成本是相同的,也许这不是渲染的问题,我会再次检查它,谢谢一个lotHello,如果你渲染一个由十个我的模板组成的模板,它会慢吗?