Skip to main content

citry-django-compressor

Route Citry component assets through django-compressor for preprocessing and minification.

Why?

Citry collects each component's CSS and JS and emits them into the page. If your project uses django-compressor for asset preprocessing (SCSS, Less, CoffeeScript, ...) and minification, this extension bridges the two.

Installation

pip install citry-django-compressor

Usage

Register the extension with your Citry instance:

from citry import Citry
from citry_django import CitryDjangoExtension
from citry_django_compressor import CitryCompressorExtension

app = Citry(
    extensions=[
        CitryDjangoExtension(),
        CitryCompressorExtension(),
    ]
)

Inline Content with Precompilation

To mark inline content for precompilation, set its type attribute to match a COMPRESS_PRECOMPILERS entry:

from citry import Component
from citry.ext.dependencies import Style, Script


class MyComponent(Component):
    class Dependencies:
        css = [
            Style(content="...", attrs={"type": "text/x-scss"}),
        ]
        js = [
            Script(content="square = (x) -> x * x", attrs={"type": "text/coffeescript"}),
        ]

File-Based Assets

For file-based assets, use the Dependencies class with a URL and type attribute. Use Django's static() to respect your STATIC_URL setting:

from django.templatetags.static import static
from citry import Component
from citry.ext.dependencies import Style


class MyComponent(Component):
    class Dependencies:
        css = [
            Style(url=static("component.scss"), attrs={"type": "text/x-scss"}),
        ]

Django-compressor will find the file via staticfiles, precompile it, and output a compressed URL.

Django Settings

Configure django-compressor as usual:

INSTALLED_APPS = [
    # ...
    "compressor",
]

STATICFILES_FINDERS = [
    # ...
    "compressor.finders.CompressorFinder",
]

COMPRESS_PRECOMPILERS = (
    ("text/x-scss", "django_libsass.SassCompiler"),
    ("text/x-sass", "django_libsass.SassCompiler"),
    ("text/less", "lessc {infile} {outfile}"),
    ("text/coffeescript", "coffee --compile --stdio"),
)

Custom File Type Mapping

By default, the extension maps these file extensions to MIME types:

Extension MIME Type
.scss text/x-scss
.sass text/x-sass
.less text/less
.styl text/stylus
.coffee text/coffeescript

Extend or override with CITRY_COMPRESSOR_FILE_TYPES:

CITRY_COMPRESSOR_FILE_TYPES = {
    ".myformat": "text/x-myformat",
}

How It Works

  1. Citry collects each component's CSS and JS during rendering
  2. Citry deduplicates identical assets (same content or URL)
  3. Before emitting, the extension's on_dependencies hook fires
  4. Assets with precompiler type attributes are collected
  5. They're fed to django-compressor's programmatic API
  6. The original dependencies are replaced with URL-based ones pointing to compressed output

Citry's $component() callbacks and js_data() work normally - they're just JavaScript content that passes through compression unchanged.

Limitations

  • css_file / js_file: When using Citry's css_file = "component.scss", the file content is inlined and the filename is not preserved. The extension cannot detect the file type automatically. Use the Dependencies class with explicit type attribute instead.

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

citry_django_compressor-0.1.0.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

citry_django_compressor-0.1.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file citry_django_compressor-0.1.0.tar.gz.

File metadata

  • Download URL: citry_django_compressor-0.1.0.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for citry_django_compressor-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c4de3eaa690ade5473a3c38d018dc1545bc563616dcf65a2891c58d1fc206554
MD5 817aa4417044c430e7230fad3a6a553a
BLAKE2b-256 2be49e6265d3150d920ea6da4c935fa4654fe289556bb20a47cd8c3384ab9a07

See more details on using hashes here.

Provenance

The following attestation bundles were made for citry_django_compressor-0.1.0.tar.gz:

Publisher: publish.yml on joeyjurjens/citry-django

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file citry_django_compressor-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for citry_django_compressor-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d1d7a5d3e78dc6a4423c00bd03b4165d52f49122d78d4eed2015ec87f7fbfcee
MD5 aae4fc27d343ad9c736ae6f6b8c1a4de
BLAKE2b-256 5531cbcccb36a5ae75f3a45ecddd1a102365992c5fd1cfd0f9bca3d087ca4ce9

See more details on using hashes here.

Provenance

The following attestation bundles were made for citry_django_compressor-0.1.0-py3-none-any.whl:

Publisher: publish.yml on joeyjurjens/citry-django

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page