Hi all, I have also been working for about a year on such a template compiler, and recently published it on Github. You may be interested in this project:
https://github.com/citylive/django-template-preprocessor ** Short summary of what already is possible, and what still needs to be done: The template preprocessor consists of two parts. -1- A compiler which compiles the template in a compact version, (removing comments, preprocessing l18n for all enabled languages, preprocessing inheritance, includes, etc..., compressing HTML, CSS and javascript, and combining external CSS/JS references.) The output is a single template directory, which is still compatible with the Django template render engine, but should render about twice as fast. -2- A second compiler which takes the already manipulated parse tree of -1-, and compiles it further into Python code. The output is a directory of .py files for all templates. This part is still experimental, and not extensively developed because it completely bypasses Django's render engine and template parser at runtime. I had the problem that it is incompatible with all custom template tags. So, they need to be rewritten. I got rendering speeds of about 20 times as fast as Django's own render engine. So, what does it does at compile-time: (a) - remove django comments - preprocess i18n tags as long as they don't contain variables. - preprocess URLs when they don't contain variables. - preprocess MEDIA_URL, SITE_DOMAIN and other static variables - preprocess inheritance. (one important incompatibility: {% extend "..." %} should only get a string as parameter, not a variable! But honestly, I really don't know why someone would do that. - preprocess {% include tags %} - don't output any {% block %} tags, because they are meaningless now. - group all {% load %} statements (b) if this is a HTML template: - parse the HTML tree. (the lexer will parse HTML in a 'django parse tree') - validation of HTML (note that we don't need to render any template for validating html) - merge internal CSS files - compress HTML (remove whitespace) - remove HTML comments - parse the CSS/javascript. - remove CSS and javascript comments. - compress css - compress javascript. (remove whitespace and shorten variable names.) Basically, we all get these optizations at compile time. A very simpel template loader will load the compiled template which renders much faster by django's engine, because it has been optimized and is much smaller now. This part is really stable. The second compiler -2-, is able to take the output, and compile it even further into python code, taking as much advantage as possible of the Python interpreter. It does also variable renaming like replacing: {% with x as long_variable %} with {% with x as y %} choosing the first free variable which has not yet been used inside the inner scope. This has been proven to work, but not yet recommended. Let me know if you have other questions. There is more I have to tell, but I'm a little busy right now... Have a nice day, Jonathan -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.