I am using Yeoman (http://yeoman.io/) as a front-end build process which concat/minifies css and javascript.
In a development environment I want separate, un-minified source to be loaded for easy debugging without having to setup Chrome Source Maps (http://code.google.com/p/closure-compiler/wiki/SourceMaps). In production the concatenated, minified source is loaded for performance.
My initial approach is to use a conditional inside my template as follows:
{% if DEVELOPEMENT %}
<!-- library -->
<script src="{{ STATIC_URL }}lib/jquery.js"></script>
<script src="{{ STATIC_URL }}lib/some_library.js"></script>
<!-- app -->
<script src="{{ STATIC_URL }}scripts/main.js"></script>
<script src="{{ STATIC_URL }}scripts/app_model.js"></script>
<script src="{{ STATIC_URL }}scripts/app_view.js"></script>
{% else %}
<script src="{{ STATIC_URL }}min/lib.min.js"></script>
<script src="{{ STATIC_URL }}min/app.min.js"></script>
{% endif %}
DEVELOPMENT is exposed to the template context using a context processor:
from django.conf import settings # import the settings file
def development(context):
return {'DEVELOPEMENT': settings.DEVELOPEMENT}
Are there any drawbacks to this method and is there a cleaner way to accomplish this in Django?
I would use your DEBUG setting which is already included in django.core.context_processors.debug.
{% if debug %}
<!-- scripts -->
{% else %}
<!-- other scripts -->
{% endif %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With