django-versioned-static 1.4.3

This little apps helps to manage your staticfiles when you need to minify them for production use. Moreover, it is capable of versioning the assets so that whenever you need to alter the static files, users won't be given old file from the browser cache.

Installation

Standard Django way:

pip install django-versioned-static

Add to your INSTALLED_APPS:

INSTALLED_APPS = (
    ..
    ..,
    'versioned_static',
    ...
)

Configure the assets themselves:

STATICS_ASSETS = {
    'css': {
        'css/mycoolproject.css': {
            'media': ('screen', 'projection', 'tv'),
            'files': ('css/jquery-ui-1.8.18.custom.css', 'css/style.css',),
            'version': 1
        },
        'css/print.css': {
            'media': ('print',),
            'files': ('css/print.css',),
            'version': 1
        }
    },
    'js': {
        'js/mycoolproject.js': {
            'files': ('js/jquery-1.7.1.min.js',
                      'js/main.js'),
            'version': 1
        }
    }
}

Done!

Usage in templates

Very simple. Use the asset template tag. Give it the static type (css or js) and the base css alias. It will generate all the necessary HTML for you directly:

{% load versioned_static_tags %}
{% asset "css" "css/mycoolproject.css" %}
{% asset "css" "css/print.css" %}
{% asset "js" "js/mycoolproject.js" %}

It takes your settings in the account. In development (when DEBUG = True), you will be given unversioned and unminified static files. When you turn the debug off, you will be given versioned asset links.

Result with DEBUG=True:

<link type="text/css" rel="stylesheet" href="/static/css/jquery-ui-1.8.18.custom.css" media="screen,projection,tv"/>
<link type="text/css" rel="stylesheet" href="/static/css/style.css" media="screen,projection,tv"/>

<link type="text/css" rel="stylesheet" href="/static/css/print.css" media="print"/>

<script type="text/javascript" src="/static/js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="/static/js/main.js"></script>

Result with DEBUG=False:

<link type="text/css" rel="stylesheet" href="/static/css/mycoolproject.1.css" media="screen,projection,tv"/>

<link type="text/css" rel="stylesheet" href="/static/css/print.1.css" media="print"/>

<script type="text/javascript" src="/static/js/mycoolproject.1.js"></script>

Minifying the files

This app features simple management command which helps you create the minified files for production. Usage goes like this:

django-admin.py minifystatics [(CSS/JS) ASSET_FILE]

Real example for previous scenario:

django-admin.py minifystatics css css/print.css

If you want to generate all the files in your app settings, simply run the command without any arguments:

django-admin.py minifystatics

The command will look in your STATIC_ROOT by default (so be sure you ran collectstatic before the minify command) and use it as the root path.

Notes

django-versioned-static internally uses YUI library for minifying the CSS/JS assets.

BSD

Author

Filip Varecha

Pip

django-versioned-static==1.4.3

Classifiers

  • Framework :: Django
  • Intended Audience :: Developers
  • Programming Language :: Python :: 2.6
  • Programming Language :: Python :: 2.7
  • Development Status :: 4 - Beta
  • Operating System :: POSIX :: Linux
  • License :: OSI Approved :: BSD License
  • Topic :: Software Development :: Libraries :: Python Modules
  • Operating System :: POSIX
  • Programming Language :: Python :: 2.5
  • Topic :: Internet :: WWW/HTTP :: Dynamic Content
File Type Python Version Uploaded On Downloads
django-versioned-static-1.4.3.tar.gz Source Aug. 28, 2012 2,690
Version Release Date
1.4.3 Aug. 28, 2012
1.4.2 June 26, 2012
1.4.1 June 20, 2012
1.4.0 June 19, 2012
1.3.1 April 14, 2012
1.3 April 12, 2012
1.2 April 12, 2012
1.1 April 9, 2012
1.0 April 9, 2012
Date Package Version Action
Aug. 26, 2015, 12:30 a.m. django-versioned-static 1.3.1 Release Created
Aug. 26, 2015, 12:30 a.m. django-versioned-static 1.3 Release Created
Aug. 26, 2015, 12:30 a.m. django-versioned-static 1.2 Release Created
Aug. 26, 2015, 12:30 a.m. django-versioned-static 1.1 Release Created
Aug. 26, 2015, 12:30 a.m. django-versioned-static 1.0 Release Created
Aug. 26, 2015, 12:30 a.m. django-versioned-static 1.4.3 Release Created
Aug. 26, 2015, 12:30 a.m. django-versioned-static 1.4.2 Release Created
Aug. 26, 2015, 12:30 a.m. django-versioned-static 1.4.1 Release Created
Aug. 26, 2015, 12:30 a.m. django-versioned-static 1.4.0 Release Created
Aug. 26, 2015, 12:30 a.m. django-versioned-static Package Created