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, ie 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'
]

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" />

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.


That is how Django Compressor works. Every time there is a change a new css file generated and used. The old one is not deleted.

Just delete all your css files in the CACHE directory and reload your page. After that there will be only one.

链接地址: http://www.djcxy.com/p/71086.html

上一篇: 当memcached被使用时压缩器仍然输出一个文件?

下一篇: Django压缩器不再生成压缩的CSS