liminspace / django-mjml

The simplest way to use MJML in Django templates.
MIT License
263 stars 32 forks source link

Is there a way to compile to HTML and Cache Results #6

Closed fission6 closed 7 years ago

fission6 commented 7 years ago

Would be great, if there isn't already, to have a way to translate MJML to HTML and keep the results as a typical HTML template (ie cache the compiled results) which would be an obvious performance gain for production.

Perhaps a management command python manage.py mjml-compile

which finds all .mjml templates and produces an .html template or finds all mjml template tags and compiles a pure HTML equivalent template.

Point is there is little reason in production to have to translate in realtime and from the docs there doesn't seem to be a consideration for this.

Nice work / project!

liminspace commented 7 years ago

I thought about it and even tried to precompile MJML-blocks, but it is not as simple as you can imagine. There are a lot of problem when you want to use filters or tags which return MJML-code. If you use precompiled MJML-blocks, you can't compile additional MJML-code there. So now I see the best way is using tcpserver mode and keep 2+ instances. It works very good, stable and it's scalable. Yes, it is a bit slower but it worths.

Also for simple templates you can just use django cache (https://docs.djangoproject.com/en/1.11/topics/cache/#template-fragment-caching) or my realization of tagged cache tcache (https://github.com/liminspace/dju-common/blob/master/dju_common/templatetags/dju_tcache.py#L44). It allows you to invalidate some tagged items of cache (https://github.com/liminspace/dju-common/blob/master/dju_common/tcache.py#L35).

Thanks for the feedback.

fission6 commented 7 years ago

Awesome work, keep it up!

On Fri, Mar 10, 2017 at 9:49 AM Igor Melnyk notifications@github.com wrote:

I thought about it and even tried to precompile MJML-blocks, but it is not as simple as you can imagine. There are a lot of problem when you want to use filters or tags which return MJML-code. If you use precompiled MJML-blocks, you can't compile additional MJML-code there. So now I see the best way is using tcpserver mode and keep 2+ instances. It works very good, stable and it's scalable. Yes, it is a bit slower but it worths.

Also for simple templates you can just use django cache ( https://docs.djangoproject.com/en/1.11/topics/cache/#template-fragment-caching ) or my realization of tagged cache tcache ( https://github.com/liminspace/dju-common/blob/master/dju_common/templatetags/dju_tcache.py#L44). It allows you to invalidate some tagged items of cache ( https://github.com/liminspace/dju-common/blob/master/dju_common/tcache.py#L35 ).

Thanks for the feedback.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/liminspace/django-mjml/issues/6#issuecomment-285687477, or mute the thread https://github.com/notifications/unsubscribe-auth/AAY9UlnVznkOcfQ9wcMqLm6WsPDAl7Llks5rkWLpgaJpZM4MYJ3w .