Django Compressor


1. Basic Compressor Configuration

COMPRESS_ENABLED = True
COMPRESS_ROOT = os.path.join(BASE_DIR, 'static/')

2. Specifying Custom Compression Settings

COMPRESS_CSS_FILTERS = [
    'compressor.filters.css_default.CssAbsoluteFilter',
    'compressor.filters.cssmin.CSSMinFilter',
]

3. Using the Output Filter to Optimize Output

COMPRESS_OUTPUT_FILTERS = ['compressor.filters.output.XhtmlOutputFilter']

4. Processing a Single File

from compressor.filters import default

filter = default.CssAbsoluteFilter(BASE_DIR)
css = filter.input('styles/main.css')

5. Compressing All Files

from django.core.management import call_command

call_command('compress')

6. Excluding Specific Files from Compression

7. Defining Custom Compression Rules

8. Using the `OutputFile' Filter to Control Output Location

9. Customizing Filter Settings

10. Handling Broken Source Files

11. Compressing JavaScript Files

12. Using the `Autoprefixer' Filter

13. Specifying the Static Root Directory

14. Using the `Exclusion' Filter

15. Customizing Error Reporting

16. Using the `Minify' Filter

17. Specifying the Base URL

18. Using the `Reorder' Filter

19. Compressing Images

20. Using the `Clean' Command

21. Using the `Verbose' Option

22. Customizing File Names

23. Using the `Filter' Class

24. Using the `Process' Command

25. Using the `Detect' Command

26. Using the `Compiler' Class

27. Using the `Block' Class

28. Using the `Compressor' Class to Process Files

29. Using the `Override' Filter

30. Using the `URL' Filter

31. Using the `Makefile' Filter

32. Using the `Merge' Filter

33. Using the `Spaceless' Filter

34. Using the `Stats' Filter

35. Using the `TemplateFilter' Filter

36. Using the `Timeline' Filter