Using Tornado Templates and Localization with Javascript

91 views
Skip to first unread message

ThereMichael

unread,
Dec 21, 2020, 9:56:39 AM12/21/20
to Tornado Web Server
One of the things we like about Tornado is that you can emit in-line (ugh) Javascript in templates and embed things like Python constants (for input field names which are shared with the Python code base) and localizations (for text and messages in we pages).

This has several disadvantages:
- JS isn't compressed
- JS is in-line

Does anyone have any ideas for better ways to do this? I've considered writing some sort of post-render processor to compress the JS, but that seems ugly and expensive. 

TIA

Michael DePalatis

unread,
Dec 21, 2020, 11:06:59 AM12/21/20
to Tornado Web Server
Hi,

A great, often overlooked feature of Tornado are UI modules. These can be used to include Javascript with a script tag (once in a template rather than once per module instance). Since this uses the standard static file handling you can get compressed responses by configuring the `tornado.web.Application` instance appropriately. I have also used webassets before which can do things like bundle and minify Javascript sources on demand.

As an aside, I'm not sure exactly about your use case, but Tornado also has built-in support for internationalization so that may be what you need.

Best,
Mike
Reply all
Reply to author
Forward
0 new messages