Skip to main content

js compiler & css minifier with sass compatibility

Project description

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:

{% load 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.

Project details


Download files

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

Source Distribution

django-shrink-0.0.3.2.tar.gz (4.7 MB view details)

Uploaded Source

File details

Details for the file django-shrink-0.0.3.2.tar.gz.

File metadata

File hashes

Hashes for django-shrink-0.0.3.2.tar.gz
Algorithm Hash digest
SHA256 92566df08e9bfb0a331380acb78cdbb90076a3acc0fb3f985c05e80449f0391f
MD5 62d59c22d96fccf30dab7014ccdd6137
BLAKE2b-256 69605747822ba5419909972dc36128fb768472c3f94677e4bec59705707a6c20

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page