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
- Citry collects each component's CSS and JS during rendering
- Citry deduplicates identical assets (same content or URL)
- Before emitting, the extension's
on_dependencieshook fires - Assets with precompiler
typeattributes are collected - They're fed to django-compressor's programmatic API
- 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'scss_file = "component.scss", the file content is inlined and the filename is not preserved. The extension cannot detect the file type automatically. Use theDependenciesclass with explicittypeattribute 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4de3eaa690ade5473a3c38d018dc1545bc563616dcf65a2891c58d1fc206554
|
|
| MD5 |
817aa4417044c430e7230fad3a6a553a
|
|
| BLAKE2b-256 |
2be49e6265d3150d920ea6da4c935fa4654fe289556bb20a47cd8c3384ab9a07
|
Provenance
The following attestation bundles were made for citry_django_compressor-0.1.0.tar.gz:
Publisher:
publish.yml on joeyjurjens/citry-django
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
citry_django_compressor-0.1.0.tar.gz -
Subject digest:
c4de3eaa690ade5473a3c38d018dc1545bc563616dcf65a2891c58d1fc206554 - Sigstore transparency entry: 2581981859
- Sigstore integration time:
-
Permalink:
joeyjurjens/citry-django@edcee5c2819ad244f87c01438ef4d2c2494d9807 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/joeyjurjens
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@edcee5c2819ad244f87c01438ef4d2c2494d9807 -
Trigger Event:
release
-
Statement type:
File details
Details for the file citry_django_compressor-0.1.0-py3-none-any.whl.
File metadata
- Download URL: citry_django_compressor-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d1d7a5d3e78dc6a4423c00bd03b4165d52f49122d78d4eed2015ec87f7fbfcee
|
|
| MD5 |
aae4fc27d343ad9c736ae6f6b8c1a4de
|
|
| BLAKE2b-256 |
5531cbcccb36a5ae75f3a45ecddd1a102365992c5fd1cfd0f9bca3d087ca4ce9
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
citry_django_compressor-0.1.0-py3-none-any.whl -
Subject digest:
d1d7a5d3e78dc6a4423c00bd03b4165d52f49122d78d4eed2015ec87f7fbfcee - Sigstore transparency entry: 2581981868
- Sigstore integration time:
-
Permalink:
joeyjurjens/citry-django@edcee5c2819ad244f87c01438ef4d2c2494d9807 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/joeyjurjens
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@edcee5c2819ad244f87c01438ef4d2c2494d9807 -
Trigger Event:
release
-
Statement type: