|
| 1 | +Django compressor |
| 2 | +================= |
| 3 | + |
| 4 | +Compresses linked and inline javascript or CSS into a single cached file. |
| 5 | + |
| 6 | +Syntax:: |
| 7 | + |
| 8 | + {% compress <js/css> %} |
| 9 | + <html of inline or linked JS/CSS> |
| 10 | + {% endcompress %} |
| 11 | + |
| 12 | +Examples:: |
| 13 | + |
| 14 | + {% compress css %} |
| 15 | + <link rel="stylesheet" href="/media/css/one.css" type="text/css" charset="utf-8"> |
| 16 | + <style type="text/css">p { border:5px solid green;}</style> |
| 17 | + <link rel="stylesheet" href="/media/css/two.css" type="text/css" charset="utf-8"> |
| 18 | + {% endcompress %} |
| 19 | + |
| 20 | +Which would be rendered something like:: |
| 21 | + |
| 22 | + <link rel="stylesheet" href="/media/CACHE/css/f7c661b7a124.css" type="text/css" media="all" charset="utf-8"> |
| 23 | + |
| 24 | +or:: |
| 25 | + |
| 26 | + {% compress js %} |
| 27 | + <script src="/media/js/one.js" type="text/javascript" charset="utf-8"></script> |
| 28 | + <script type="text/javascript" charset="utf-8">obj.value = "value";</script> |
| 29 | + {% endcompress %} |
| 30 | + |
| 31 | +Which would be rendered something like:: |
| 32 | + |
| 33 | + <script type="text/javascript" src="/media/CACHE/js/3f33b9146e12.js" charset="utf-8"></script> |
| 34 | + |
| 35 | +Linked files must be on your COMPRESS_URL (which defaults to MEDIA_URL). |
| 36 | +If DEBUG is true off-site files will throw exceptions. If DEBUG is false |
| 37 | +they will be silently stripped. |
| 38 | + |
| 39 | +If COMPRESS is False (defaults to the opposite of DEBUG) the compress tag |
| 40 | +simply returns exactly what it was given, to ease development. |
| 41 | + |
| 42 | + |
| 43 | +Settings |
| 44 | +******** |
| 45 | + |
| 46 | +Django compressor has a number of settings that control it's behavior. |
| 47 | +They've been given sensible defaults. |
| 48 | + |
| 49 | +`COMPRESS` default: the opposite of `DEBUG` |
| 50 | + Boolean that decides if compression will happen. |
| 51 | + |
| 52 | +`COMPRESS_URL` default: `MEDIA_URL` |
| 53 | + Controls the URL that linked media will be read from and compressed media |
| 54 | + will be written to. |
| 55 | + |
| 56 | +`COMPRESS_ROOT` default: `MEDIA_ROOT` |
| 57 | + Controls the absolute file path that linked media will be read from and |
| 58 | + compressed media will be written to. |
| 59 | + |
| 60 | +`COMPRESS_OUTPUT_DIR` default: `CACHE` |
| 61 | + Conttrols the directory inside `COMPRESS_ROOT` that compressed files will |
| 62 | + be written to. |
| 63 | + |
| 64 | +`COMPRESS_CSS_FILTERS` default: [] |
| 65 | + A list of filters that will be applied to CSS. |
| 66 | + |
| 67 | +`COMPRESS_JS_FILTERS` default: ['compressor.filters.jsmin.JSMinFilter']) |
| 68 | + A list of filters that will be applied to javascript. |
0 commit comments