Django-compressor: JS files are minified by default, but CSS files are not

Created on 8 Nov 2017  ·  10Comments  ·  Source: django-compressor/django-compressor

Hi, I am using Django(1.8.2) and django-compressor(2.2). The compressed js works good, however, the css file is not compressed.

Here is part of my template:

{% load staticfiles %}
{% load compress %}
{% compress css %}
<link rel="stylesheet" href="{% static 'landing/style.css' %}" type="text/css"></head>
{% endcompress %}
{% compress js %}
<script src="{% static 'landing/js/jquery.min.js' %}"></script>
<script src="{% static 'landing/js/ads.js' %}"></script>
<script src="{% static 'landing/js/ads.js' %}"></script>
{% endcompress %}

It do generate a css file, but it is exactly the same with the original file.

feature

Most helpful comment

I see. This line works:

COMPRESS_CSS_FILTERS = ['compressor.filters.css_default.CssAbsoluteFilter', 'compressor.filters.cssmin.rCSSMinFilter']

Thank you.

All 10 comments

please post your settings.py.

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'compressor',
)

STATIC_URL = '/static/'

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),
]

STATICFILES_FINDERS = (
  'django.contrib.staticfiles.finders.FileSystemFinder',
  'django.contrib.staticfiles.finders.AppDirectoriesFinder',
  'compressor.finders.CompressorFinder',
)

COMPRESS_ENABLED = True
COMPRESS_OUTPUT_DIR = 'compress'
STATIC_ROOT = '/home/service/growth/static_file/static'

css is not compressed by default, see the default setting here: https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_CSS_FILTERS. i admit it is weird that this is done for js by default and not for css. but we probably won't change that unless we do some release with other major breaking changes.

Sorry, I am not familiar with CSS. Should I set the COMPRESS_CSS_FILTERS variable to make it work for css? Which option should I use?

I see. This line works:

COMPRESS_CSS_FILTERS = ['compressor.filters.css_default.CssAbsoluteFilter', 'compressor.filters.cssmin.rCSSMinFilter']

Thank you.

i'll leave this open so we can discuss this in case we make such a release.

Under these circumstances I please remove rcssmin from setup.py:install_requires and state the current misconception in some obvious place in the documentation, like under 'Usage'.

@dilyanpalauzov you are welcome to create a pull request for that, i don't know when i will find the time to do it myself.

edit: ...actually, i would rather think of this as a bug and having rcssmin installed by default makes it easier for the user to work around it, so i would leave that as a requirement. however, the documentation would of course benefit from making this more obvious.

FYI. Just installed django-compressor and ended up here because I expected CSS to be minified as my JS was.

I see. This line works:

COMPRESS_CSS_FILTERS = ['compressor.filters.css_default.CssAbsoluteFilter', 'compressor.filters.cssmin.rCSSMinFilter']

Thank you.

But how can I get the min.js or min.css for the compressed files?

Was this page helpful?
0 / 5 - 0 ratings