Skip to main content

django-shrink

A js compiler & css minifier with sass compatibility

Requirements

  • Django 1.3+

  • 2.6 <= Python < 3

  • Java for compiling and compressing

  • django.contrib.staticfiles in INSTALLED_APPS

Installation

pip install django-shrink

Configuration

INSTALLED_APPS = (
    ...
    'django.contrib.staticfiles',
    ...
    'shrink',
    ...
)

Optionally if you want to use Sass you need to add the compilation view to your urls:

# urls.py
urlpatterns = patterns('',
    ...
    (r'', include('shrink.urls')),
    ...
)

Usage

Define your javascripts and css files in your template as in this example:

{% import shrink %}
{% styles css/myproject-min.css %}
    css/reset.css
    css/forms.css
    css/myproject.scss
{% endstyles %}
{% scripts js/myproject-min.js %}
    js/jquery.js
    js/plugin.js
    js/myproject.js
{% endscripts %}

When DEBUG = True this will end up as:

<link rel="stylesheet" href="{{ STATIC_URL }}css/reset.css">
<link rel="stylesheet" href="{{ STATIC_URL }}css/forms.css">
<link rel="stylesheet" href="{{ STATIC_URL }}css/myproject.scss">
<script src="{{ STATIC_URL }}js/jquery.js"></script>
<script src="{{ STATIC_URL }}js/plugin.js"></script>
<script src="{{ STATIC_URL }}js/myproject.js"></script>

When DEBUG = False this will end up as:

<link rel="stylesheet" href="{{ STATIC_URL }}css/myproject-min.css?timestamp">
<script src="{{ STATIC_URL }}js/myproject-min.js?timestamp"></script>

When deploying you want to compile your javascripts, compile your scss (Sass) and compress the css files. django-shrink overrides the collectstatic management command and after collecting the static files it does the compiling and compressing. Thus you need to execute the management command collectstatic in your deployment environment.

Settings

SHRINK_TIMESTAMP

Controls if you want to timestamp the compressed/compiled assets.

  • Default: True

SHRINK_STORAGE

Storage for the compressed/compiled assets.

  • Default: settings.STATICFILES_STORAGE

SHRINK_CLOSURE_COMPILER

Path to Google Closure Compiler jar.

  • Default: Google Closure Compiler jar provided.

SHRINK_CLOSURE_COMPILER_COMPILATION_LEVEL

Google Closure Compiler optimization level.

  • Default: 'SIMPLE_OPTIMIZATIONS'

SHRINK_YUI_COMPRESSOR

Path to YUI Compressor

  • Default: YUI compressor jar provided.

Metadata

Release files for django-shrink 0.0.3.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-shrink 0.0.3.3
File Size Uploaded Provenance Actions
django-shrink-0.0.3.3.tar.gz 4.7 MB Without provenance Details for django-shrink-0.0.3.3.tar.gz

Release files / django-shrink-0.0.3.3.tar.gz

Download URL django-shrink-0.0.3.3.tar.gz
Size 4.7 MB
Tags Source
SHA-256 checksum
How to use checksums
c6c70880ae7bb14f233a095e0cc91f5cc1e87f29da45b9ab515dd28270f2800d
BLAKE2b-256 checksum
How to use checksums
6f6b9d9f5d409e8190db233e98cff184bc66dc1936a0ddccf5ded18bdd963a73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for django-shrink 0.0.3.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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