Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Compressor Not Regenerating Compressed CSS

I was experimenting with Django Compressor in development on a block of css files. I first put {% compress %} tags around one file, generating f6527e81a37c.css. Then I included two more css files between the tags, but instead of one minified file, this resulted in 2 minified files: f6527e81a37c.css and ee906624f953.css.

In the end, I wanted to concat and compress all of that css block into one minified file, but moving more files into the compress tags doesn't seem to regenerate the keys associated with the css files, i.e. it still compresses into multiple css files even though they're wrapped in the same {% compress %} block.

I tried clearing Django's memcache, removing the /static/CACHE/ directory that the Compressor generates, and using the compress management command that comes with Django Compressor, but I'm still getting multiple compressed css files when I run the dev environment. Is there some sort of refresh I can do so that Django Compressor regenerates the css keys associated with files in the {% compress %} block? The Compressor must be storing how previous compressed file keys somewhere.

The results of compression:

<link rel="stylesheet" href="/static/CACHE/css/f6527e81a37c.css" type="text/css" media="screen, projection" />
<link rel="stylesheet" href="/static/CACHE/css/ee906624f953.css" type="text/css" />
<link rel="stylesheet" href="/static/CACHE/css/7147db857125.css" type="text/css" media="screen, projection" />
<link rel="stylesheet" href="/static/CACHE/css/043e7d82b775.css" type="text/css" />

settings.py:

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    #other
    'compressor.finders.CompressorFinder',
)
COMPRESS_ENABLED = True
COMPRESS_OFFLINE = True
COMPRESS_CSS_FILTERS = [
    #creates absolute urls from relative ones
    'compressor.filters.css_default.CssAbsoluteFilter',
    #css minimizer
    'compressor.filters.cssmin.CSSMinFilter'
]
COMPRESS_JS_FILTERS = [
    'compressor.filters.jsmin.JSMinFilter'
]
like image 572
Cosmo Avatar asked Jun 20 '12 07:06

Cosmo


2 Answers

Set same media property to all CSS declarations will help.

The result is something like:

<link rel="stylesheet" href="/static/CACHE/css/f6527e81a37c.css" type="text/css" media="all" />
like image 185
Coc B. Avatar answered Oct 21 '22 03:10

Coc B.


I found my answer:

Django Compressor was breaking the css files up around those that contain media="screen, projection" in their properties and those that don't.

Thanks for the response.

like image 22
Cosmo Avatar answered Oct 21 '22 05:10

Cosmo