Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xaralis/django-versioned-static
Lightweight application for managing versioned static files and minifying them for production use.
https://github.com/xaralis/django-versioned-static
Last synced: 2 months ago
JSON representation
Lightweight application for managing versioned static files and minifying them for production use.
- Host: GitHub
- URL: https://github.com/xaralis/django-versioned-static
- Owner: xaralis
- Created: 2012-04-09T17:25:16.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2016-09-05T11:13:47.000Z (over 8 years ago)
- Last Synced: 2024-10-12T00:42:18.034Z (4 months ago)
- Language: Python
- Homepage:
- Size: 26.4 KB
- Stars: 6
- Watchers: 2
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.rst
Awesome Lists containing this project
README
django-versioned-static
------------------------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**::
**Result with DEBUG=False**::
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.