Search code examples
pythontornado

Strip unnecessary whitespace and html comments from Tornado-rendered Pages


I am using tornado and the tornado templating engine. Even when debug is set to False, tornado-rendered pages still have HTML comments and unnecessary whitespace in them. Is there a setting to automatically strip this out when rendering pages (essentially minifying the rendered pages)?


Solution

  • Tornado doesn't know anything about html comments, so any html comments will be passed through as-is. (You can use {# #} to add comments to your templates). There is limited support for stripping whitespace, which is enabled by default based on file extension (.html and .js). There's also a half-implemented compress_whitespace setting, although there is no clean way to set it unless you implement your own template loader.