Repository: django-compressor/django-compressor

Issue:
JS files are minified by default, but CSS files are not
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:
```html
{% 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.


Discussion:
please post your settings.py.
```python
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?
Any new release in sight that would change the default for (not) minifying CSS?

Resolving patch:
diff --git a/compressor/conf.py b/compressor/conf.py
--- a/compressor/conf.py
+++ b/compressor/conf.py
@@ -6,9 +6,13 @@
 from appconf import AppConf
 
 
-default_filters = dict(
-    css=['compressor.filters.css_default.CssAbsoluteFilter'],
-    js=['compressor.filters.jsmin.JSMinFilter'])
+default_filters = {
+    'css': [
+        'compressor.filters.css_default.CssAbsoluteFilter',
+        'compressor.filters.cssmin.rCSSMinFilter'
+    ],
+    'js': ['compressor.filters.jsmin.rJSMinFilter']
+}
 
 
 class CompressorConf(AppConf):


Test patch:
diff --git a/compressor/tests/test_base.py b/compressor/tests/test_base.py
--- a/compressor/tests/test_base.py
+++ b/compressor/tests/test_base.py
@@ -12,7 +12,7 @@
 
 from compressor import cache as cachemod
 from compressor.base import SOURCE_FILE, SOURCE_HUNK
-from compressor.cache import get_cachekey, get_precompiler_cachekey, get_hexdigest
+from compressor.cache import get_cachekey, get_precompiler_cachekey
 from compressor.conf import settings
 from compressor.css import CssCompressor
 from compressor.exceptions import FilterDoesNotExist, FilterError
@@ -186,12 +186,12 @@ def test_cachekey(self):
             r"cachekey is returning something that doesn't look like r'\w{12}'")
 
     def test_css_return_if_on(self):
-        output = css_tag('/static/CACHE/css/58a8c0714e59.css')
+        output = css_tag('/static/CACHE/css/600674ea1d3d.css')
         self.assertEqual(output, self.css_node.output().strip())
 
     def test_css_preload_output(self):
         # this needs to have the same hash as in the test above
-        out = '<link rel="preload" href="/static/CACHE/css/58a8c0714e59.css" as="style" />'
+        out = '<link rel="preload" href="/static/CACHE/css/600674ea1d3d.css" as="style" />'
         self.assertEqual(out, self.css_node.output(mode="preload"))
 
     def test_js_split(self):
@@ -233,7 +233,7 @@ def test_js_override_url(self):
 
     def test_css_override_url(self):
         self.css_node.context.update({'url': 'This is not a url, just a text'})
-        output = css_tag('/static/CACHE/css/58a8c0714e59.css')
+        output = css_tag('/static/CACHE/css/600674ea1d3d.css')
         self.assertEqual(output, self.css_node.output().strip())
 
     @override_settings(COMPRESS_PRECOMPILERS=(), COMPRESS_ENABLED=False)
@@ -291,7 +291,7 @@ def test_template_precompiler(self):
         css = '<style type="text/django">p { border:10px solid {% if 1 %}green{% else %}red{% endif %};}</style>'
         css_node = CssCompressor('css', css)
         output = make_soup(css_node.output('inline'))
-        self.assertEqual(output.text, 'p { border:10px solid green;}')
+        self.assertEqual(output.text, 'p{border:10px solid green}')
 
 
 class CssMediaTestCase(SimpleTestCase):
@@ -410,6 +410,7 @@ class CompressorInDebugModeTestCase(SimpleTestCase):
 
     def setUp(self):
         self.css = '<link rel="stylesheet" href="/static/css/one.css" type="text/css" />'
+        self.expected_css_hash = '5c6a60375256'
         self.tmpdir = mkdtemp()
         new_static_root = os.path.join(self.tmpdir, "static")
         copytree(settings.STATIC_ROOT, new_static_root)
@@ -432,25 +433,27 @@ def tearDown(self):
     def test_filename_in_debug_mode(self):
         # In debug mode, compressor should look for files using staticfiles
         # finders only, and not look into the global static directory, where
-        # files can be outdated
-        css_filename = os.path.join(settings.COMPRESS_ROOT, "css", "one.css")
-        # Store the hash of the original file's content
-        with open(css_filename) as f:
-            css_content = f.read()
-        hashed = get_hexdigest(css_content, 12)
-        # Now modify the file in the STATIC_ROOT
+        # files can be outdated. So compressor's output shouldn't change from
+        # the one pre-generated if we modify the file in STATIC_ROOT.
+        def compare():
+            expected = '<link rel="stylesheet" href="/static/CACHE/css/%s.css" type="text/css">' % self.expected_css_hash
+            compressor = CssCompressor('css', self.css)
+            compressor.storage = DefaultStorage()
+            output = compressor.output()
+            self.assertEqual(expected, output)
+
+        compare()
+
+        filename = os.path.join(settings.COMPRESS_ROOT, "css", "one.css")
         test_css_content = "p { font-family: 'test' }"
-        with open(css_filename, "a") as css:
+        with open(filename, "a") as css:
             css.write("\n")
             css.write(test_css_content)
-        # We should generate a link with the hash of the original content, not
-        # the modified one
-        expected = '<link rel="stylesheet" href="/static/CACHE/css/%s.css" type="text/css">' % hashed
-        compressor = CssCompressor('css', self.css)
-        compressor.storage = DefaultStorage()
-        output = compressor.output()
-        self.assertEqual(expected, output)
-        with open(os.path.join(settings.COMPRESS_ROOT, "CACHE", "css",
-                               "%s.css" % hashed), "r") as f:
+        compare()
+
+        result_filename = os.path.join(
+            settings.COMPRESS_ROOT, "CACHE", "css",
+            "%s.css" % self.expected_css_hash)
+        with open(result_filename, "r") as f:
             result = f.read()
         self.assertTrue(test_css_content not in result)
diff --git a/compressor/tests/test_conf.py b/compressor/tests/test_conf.py
--- a/compressor/tests/test_conf.py
+++ b/compressor/tests/test_conf.py
@@ -5,8 +5,11 @@
 from compressor.conf import CompressorConf
 
 
-default_css_filters = ['compressor.filters.css_default.CssAbsoluteFilter']
-default_js_filters = ['compressor.filters.jsmin.JSMinFilter']
+default_css_filters = [
+    'compressor.filters.css_default.CssAbsoluteFilter',
+    'compressor.filters.cssmin.rCSSMinFilter'
+]
+default_js_filters = ['compressor.filters.jsmin.rJSMinFilter']
 
 
 def create_conf(**attrs):
diff --git a/compressor/tests/test_jinja2ext.py b/compressor/tests/test_jinja2ext.py
--- a/compressor/tests/test_jinja2ext.py
+++ b/compressor/tests/test_jinja2ext.py
@@ -74,7 +74,7 @@ def test_css_tag(self):
         <link rel="stylesheet" href="{{ STATIC_URL }}css/two.css" type="text/css" charset="utf-8">
         {% endcompress %}""")
         context = {'STATIC_URL': settings.COMPRESS_URL}
-        out = css_tag("/static/CACHE/css/output.58a8c0714e59.css")
+        out = css_tag("/static/CACHE/css/output.600674ea1d3d.css")
         self.assertEqual(out, template.render(context))
 
     def test_nonascii_css_tag(self):
@@ -83,7 +83,7 @@ def test_nonascii_css_tag(self):
         <style type="text/css">p { border:5px solid green;}</style>
         {% endcompress %}""")
         context = {'STATIC_URL': settings.COMPRESS_URL}
-        out = css_tag("/static/CACHE/css/output.4263023f49d6.css")
+        out = css_tag("/static/CACHE/css/output.d5444a1ab4a3.css")
         self.assertEqual(out, template.render(context))
 
     def test_js_tag(self):
@@ -119,10 +119,10 @@ def test_css_inline(self):
         <style type="text/css">p { border:5px solid green;}</style>
         {% endcompress %}""")
         context = {'STATIC_URL': settings.COMPRESS_URL}
-        out = '\n'.join([
-            '<style type="text/css">body { background:#990; }',
-            'p { border:5px solid green;}</style>',
-        ])
+        out = (
+            '<style type="text/css">body{background:#990}'
+            'p{border:5px solid green}</style>'
+        )
         self.assertEqual(out, template.render(context))
 
     def test_js_inline(self):
@@ -140,6 +140,6 @@ def test_nonascii_inline_css(self):
                                             '<style type="text/css">'
                                             '/* русский текст */'
                                             '</style>{% endcompress %}')
-        out = '<link rel="stylesheet" href="/static/CACHE/css/output.c836c9caed5c.css" type="text/css">'
+        out = '<link rel="stylesheet" href="/static/CACHE/css/output.e3b0c44298fc.css" type="text/css">'
         context = {'STATIC_URL': settings.COMPRESS_URL}
         self.assertEqual(out, template.render(context))
diff --git a/compressor/tests/test_offline.py b/compressor/tests/test_offline.py
--- a/compressor/tests/test_offline.py
+++ b/compressor/tests/test_offline.py
@@ -590,8 +590,8 @@ def _test_offline(self, engine):
             # 'compress' nodes are processed correctly.
             self.assertEqual(4, count)
             self.assertEqual(engine, 'jinja2')
-            self.assertIn(self._render_link('7ff52cb38987'), result)
-            self.assertIn(self._render_link('2db2b4d36380'), result)
+            self.assertIn(self._render_link('187e2ce75808'), result)
+            self.assertIn(self._render_link('fffafcdf428e'), result)
 
         self.assertIn(self._render_script('eeabdac29232'), result)
         self.assertIn(self._render_script('9a7f06880ce3'), result)
diff --git a/compressor/tests/test_sekizai.py b/compressor/tests/test_sekizai.py
--- a/compressor/tests/test_sekizai.py
+++ b/compressor/tests/test_sekizai.py
@@ -36,4 +36,4 @@ def test_postprocess_css(self):
         html = template.render(context).strip()
         self.assertEqual(html,
 '''<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.5/css/select2.min.css" rel="stylesheet" type="text/css">
-<link rel="stylesheet" href="/static/CACHE/css/output.20f9b535162f.css" type="text/css">''')
+<link rel="stylesheet" href="/static/CACHE/css/output.44f040b05f91.css" type="text/css">''')
diff --git a/compressor/tests/test_storages.py b/compressor/tests/test_storages.py
--- a/compressor/tests/test_storages.py
+++ b/compressor/tests/test_storages.py
@@ -59,5 +59,5 @@ def test_css_tag_with_storage(self):
         {% endcompress %}
         """
         context = {'STATIC_URL': settings.COMPRESS_URL}
-        out = css_tag("/static/CACHE/css/output.aca9bcd16bee.css")
+        out = css_tag("/static/CACHE/css/output.e701f86c6430.css")
         self.assertEqual(out, render(template, context))
diff --git a/compressor/tests/test_templatetags.py b/compressor/tests/test_templatetags.py
--- a/compressor/tests/test_templatetags.py
+++ b/compressor/tests/test_templatetags.py
@@ -40,7 +40,7 @@ def test_css_tag(self):
 <style type="text/css">p { border:5px solid green;}</style>
 <link rel="stylesheet" href="{{ STATIC_URL }}css/two.css" type="text/css">
 {% endcompress %}"""
-        out = css_tag("/static/CACHE/css/output.58a8c0714e59.css")
+        out = css_tag("/static/CACHE/css/output.600674ea1d3d.css")
         self.assertEqual(out, render(template, self.context))
 
     def test_css_tag_with_block(self):
@@ -49,7 +49,7 @@ def test_css_tag_with_block(self):
 <style type="text/css">p { border:5px solid blue;}</style>
 <link rel="stylesheet" href="{{ STATIC_URL }}css/two.css" type="text/css">
 {% endcompress %}"""
-        out = css_tag("/static/CACHE/css/block_name.393dbcddb48e.css")
+        out = css_tag("/static/CACHE/css/block_name.a1e074d0c4ac.css")
         self.assertEqual(out, render(template, self.context))
 
     def test_missing_rel_leaves_empty_result(self):
@@ -66,7 +66,7 @@ def test_missing_rel_only_on_one_resource(self):
 <style type="text/css">p { border:5px solid green;}</style>
 <link rel="stylesheet" href="{{ STATIC_URL }}css/two.css" type="text/css">
 {% endcompress %}"""
-        out = css_tag("/static/CACHE/css/output.58a8c0714e59.css")
+        out = css_tag("/static/CACHE/css/output.600674ea1d3d.css")
         self.assertEqual(out, render(template, self.context))
 
     def test_uppercase_rel(self):
@@ -75,7 +75,7 @@ def test_uppercase_rel(self):
 <style type="text/css">p { border:5px solid green;}</style>
 <link rel="StyleSheet" href="{{ STATIC_URL }}css/two.css" type="text/css">
 {% endcompress %}"""
-        out = css_tag("/static/CACHE/css/output.58a8c0714e59.css")
+        out = css_tag("/static/CACHE/css/output.600674ea1d3d.css")
         self.assertEqual(out, render(template, self.context))
 
     def test_nonascii_css_tag(self):
@@ -84,7 +84,7 @@ def test_nonascii_css_tag(self):
         <style type="text/css">p { border:5px solid green;}</style>
         {% endcompress %}
         """
-        out = css_tag("/static/CACHE/css/output.4263023f49d6.css")
+        out = css_tag("/static/CACHE/css/output.d5444a1ab4a3.css")
         self.assertEqual(out, render(template, self.context))
 
     def test_js_tag(self):
@@ -145,11 +145,10 @@ def test_inline(self):
         <style type="text/css">p { border:5px solid green;}</style>
         <link rel="stylesheet" href="{{ STATIC_URL }}css/two.css" type="text/css">
         {% endcompress %}"""
-
         out_js = '<script>obj={};;obj.value="value";;</script>'
-        out_css = '\n'.join(('<style type="text/css">body { background:#990; }',
-                             'p { border:5px solid green;}',
-                             'body { color:#fff; }</style>'))
+        out_css = ('<style type="text/css">body{background:#990}'
+                   'p{border:5px solid green}'
+                   'body{color:#fff}</style>')
         self.assertEqual(out_js + out_css, render(template, self.context))
 
     def test_named_compress_tag(self):