• Blogs (9)
    • 📱 236 - 992 - 3846

      📧 jxjwilliam@gmail.com

    • Version: ‍🚀 1.1.0
  • Smarty: HTML comment and net traffic

    Blogs20112011-10-05


    Smarty: HTML comment

    Sometimes when modifying HTML files, we are accustomed to using HTML comment to temporarily comment some codes, in case of later reuse. To do this in Smarty templates file need to be very careful, because the comment codes might cause bad results. Like the following:

    {Smarty comment: The following HTML comment is not SAFE and harmful!}
    <!--div id="div_list"> {include file="{$template}"} </div-->

    The above statement will cause very big leak: instead of ignoring this statement, Smarty actually parses and executes this statement, fills up HTML with file {$templates}, and finally, comment them with ! e.g.: the Smarty {$template} generates 1000 lines output, then use to comment them, hide the output. This largely decreases the script performance. Put the comment here is very bad: cause network traffic, and decrease the performance. This might be a bug of Smarty, and should not happen when HTML has already comment the statement. However it does.

    The solution: Just remove it, to make codes clean.