This article describes how to use the compression component DjangoCompressor in the Python Django framework. This tool is mainly used to compress jscss. For more information about how to speed up website loading, we usually need to compress JavaScript code and css code. It is time-consuming and labor-consuming to manually compress these js and css files.
Django Compressor can achieve automatic compression of js/css. Django Compressor is very easy to use and can work normally after simple settings are made according to the document. We strongly recommend that you read the entire document (the document is short ).
In use, you only need to put css/js in The compress tag Django Compressor to automatically process it. In debug mode, Django Compressor does not perform any processing. In non-debug mode, Django Compressor automatically compresses js/css files and outputs the compressed files to the STATIC_ROOT directory of django. Therefore, make sure that the STATIC_ROOT directory is correctly set.
{% load compress %}{% compress
[
[block_name]] %}{% endcompress %}{% compress css %}
{% endcompress %}
Supported coffeescript and less
In the development phase, coffeescript and less can be processed directly using js. the loading speed should be pre-compiled into js and css. Django Compressor provides COMPRESS_PRECOMPILERS settings to pre-process data based on the type.
COMPRESS_PRECOMPILERS = ( ('text/coffeescript', 'coffee --compile --stdio'), ('text/less', 'lessc {infile} {outfile}'), ('text/x-sass', 'sass {infile} {outfile}'), ('text/x-scss', 'sass --scss {infile} {outfile}'),)