-->

Django-Compress compressJs/CSS of your application forbetter performance of the application

By: Varghese Chacko 1 year, 5 months ago

Django-compress is a Django application that allows us to compress our CSS andJavascript for better performance of the the application. The django compress provides a tag named compress that takes the typr to compress, namely, css and js.  The compressor combines the CSS/JS contained in the tag and save as a single file in static directory. Default location is <STATIC DIRECTORY>/CACHE

First we need to load the compress and then use it tocompress JS and CSS. For example

Loader.

{% load compress %}

CSS:

{% compress css %}
<link rel="stylesheet" href="/static/css/one.css" type="text/css" charset="utf-8">
<style type="text/css">p { border:5px solid green;}</style>
<link rel="stylesheet" href="/static/css/two.css" type="text/css" charset="utf-8">
{% endcompress %}

Result:

<link rel="stylesheet" href="/static/CACHE/css/output.fwew7c6we61bew7a124.css" type="text/css" charset="utf-8">

JS:

{% compress js inline %}
<script src="/static/js/one.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">obj.value = "value";</script>
{% endcompress %}

Result:

<script src="/static/CACHE/css/output.f345345s45b7a124.js" type="text/javascript" charset="utf-8"></script>

Adding an argument inline will put the script inline instead of page.

Wish to hire us?

We take the vision which comes from dreams and apply the magic of science and mathematics, adding the heritage of our profession and our knowledge to create a design.