Search code examples
cssdjangodjango-compressor

Why is django-compressor modifying CSS files instead of simply concatenating them?


I have recently deployed a Django-based site. I was looking for ways to speed up page loads, so I decided to give django-compressor a try.

My home page includes quite a few CSS and JS files, so django-compressor seemed like the perfect tool for the job. I modified the template for the home page to take advantage of django-compressor's CSS concatenation capabilities:

{% compress css %}
  <link href="{{ STATIC_URL }}css/file1.css" rel="stylesheet" />
  <link href="{{ STATIC_URL }}css/file2.css" rel="stylesheet" />
{% endcompress %}

Unfortunately, the problem is that django-compressor is modifying the files. file1.css contains a large number of declarations and file2.css contains some new declarations and overrides some of the declarations in file1.css. Unfortunately some of the declarations in file2.css are missing (part of the file is there - but part of it isn't).

This still happens even when I set:

COMPRESS_CSS_FILTERS = []

...in settings.py. The files are concatenated but some of file2.css's declarations are missing. Is there some setting I don't know about that is causing the file to be modified or declarations to be dropped? Nothing like this happens with the JavaScript files.


Solution

  • Turns out the problem was that I forgot to run:

    python manage.py collectstatic
    

    ...and therefore the missing attributes were due to the fact that the static directory contained an older copy of the CSS file.