acdha / django_compressor forked from mintchaos/django_compressor
- Source
- Commits
- Network (13)
- Downloads (0)
- Wiki (1)
- Graphs
-
Branch:
master
| name | age | message | |
|---|---|---|---|
| |
.gitignore | Thu Apr 30 01:31:20 -0700 2009 | |
| |
AUTHORS | Thu Apr 30 01:31:20 -0700 2009 | |
| |
LICENSE | Thu Apr 30 01:31:20 -0700 2009 | |
| |
MANIFEST.in | Thu Apr 30 01:31:20 -0700 2009 | |
| |
README.rst | Sun Nov 08 13:33:44 -0800 2009 | |
| |
compressor/ | ||
| |
setup.py | Sun Oct 18 12:44:41 -0700 2009 | |
| |
tests/ | Thu Apr 30 14:04:01 -0700 2009 |
Django compressor
Compresses linked and inline javascript or CSS into a single cached file.
Syntax:
{% compress <js/css> %}
<html of inline or linked JS/CSS>
{% endcompress %}
Examples:
{% compress css %}
<link rel="stylesheet" href="/media/css/one.css" type="text/css" charset="utf-8">
<style type="text/css">p { border:5px solid green;}</style>
<link rel="stylesheet" href="/media/css/two.css" type="text/css" charset="utf-8">
{% endcompress %}
Which would be rendered something like:
<link rel="stylesheet" href="/media/CACHE/css/f7c661b7a124.css" type="text/css" media="all" charset="utf-8">
or:
{% compress js %}
<script src="/media/js/one.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">obj.value = "value";</script>
{% endcompress %}
Which would be rendered something like:
<script type="text/javascript" src="/media/CACHE/js/3f33b9146e12.js" charset="utf-8"></script>
Linked files must be on your COMPRESS_URL (which defaults to MEDIA_URL). If DEBUG is true off-site files will throw exceptions. If DEBUG is false they will be silently stripped.
If COMPRESS is False (defaults to the opposite of DEBUG) the compress tag simply returns exactly what it was given, to ease development.
CSS Notes:
All relative url() bits specified in linked CSS files are automatically converted to absolute URLs while being processed. Any local absolute urls (those starting with a '/') are left alone.
Stylesheets that are @import'd are not compressed into the main file. They are left alone.
Set the media attribute as normal on your <style> and <link> elements and the combined CSS will be wrapped in @media blocks as necessary.
Recomendations:
- Use only relative or full domain absolute urls in your CSS files.
- Avoid @import! Simply list all your CSS files in the HTML, they'll be combined anyway.
Why another static file combiner for django?
Short version: None of them did exactly what I needed.
Long version:
Settings
Django compressor has a number of settings that control it's behavior. They've been given sensible defaults.
Dependecies
- BeautifulSoup
Known fails
- Non ASCII characters in linked CSS files cause breakage. See issue 3 for details. And carljm's branch for a work around if you're running into this problem. The goal is to get it standardized on unicode all the way through.

