PageRenderTime 83ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

ReStructuredText | 71 lines | 55 code | 16 blank | 0 comment | 0 complexity | dede46b56b8477025f2e04b4a003170d MD5 | raw file
  1. Django Compressor
  2. =================
  3. .. image::
  4. :alt: Build Status
  5. :target:
  6. Django Compressor combines and compresses linked and inline Javascript
  7. or CSS in a Django templates into cacheable static files by using the
  8. ``compress`` template tag.
  9. HTML in between ``{% compress js/css %}`` and ``{% endcompress %}`` is
  10. parsed and searched for CSS or JS. These styles and scripts are subsequently
  11. processed with optional, configurable compilers and filters.
  12. The default filter for CSS rewrites paths to static files to be absolute
  13. and adds a cache busting timestamp. For Javascript the default filter
  14. compresses it using ``jsmin``.
  15. As the final result the template tag outputs a ``<script>`` or ``<link>``
  16. tag pointing to the optimized file. These files are stored inside a folder
  17. and given an unique name based on their content. Alternatively it can also
  18. return the resulting content to the original template directly.
  19. Since the file name is dependend on the content these files can be given
  20. a far future expiration date without worrying about stale browser caches.
  21. The concatenation and compressing process can also be jump started outside
  22. of the request/response cycle by using the Django management command
  23. `` compress``.
  24. Configurability & Extendibility
  25. -------------------------------
  26. Django Compressor is highly configurable and extendible. The HTML parsing
  27. is done using lxml_ or if it's not available Python's built-in HTMLParser by
  28. default. As an alternative Django Compressor provides a BeautifulSoup_ and a
  29. html5lib_ based parser, as well as an abstract base class that makes it easy to
  30. write a custom parser.
  31. Django Compressor also comes with built-in support for `CSS Tidy`_,
  32. `YUI CSS and JS`_ compressor, the Google's `Closure Compiler`_, a Python
  33. port of Douglas Crockford's JSmin_, a Python port of the YUI CSS Compressor
  34. cssmin_ and a filter to convert (some) images into `data URIs`_.
  35. If your setup requires a different compressor or other post-processing
  36. tool it will be fairly easy to implement a custom filter. Simply extend
  37. from one of the available base classes.
  38. More documentation about the usage and settings of Django Compressor can be
  39. found on ``_.
  40. The source code for Django Compressor can be found and contributed to on
  41. ``_. There you can also file tickets.
  42. The `in-development version`_ of Django Compressor can be installed with
  43. ``pip install django_compressor==dev`` or ``easy_install django_compressor==dev``.
  44. .. _BeautifulSoup:
  45. .. _lxml:
  46. .. _html5lib:
  47. .. _CSS Tidy:
  48. .. _YUI CSS and JS:
  49. .. _Closure Compiler:
  50. .. _JSMin:
  51. .. _cssmin:
  52. .. _data URIs:
  53. ..
  54. ..
  55. .. _in-development version: