Django module for managing js, (s)css and other website resources.
- Merges and compresses javascript and scss files into one
- Manages serial numbers for resource URLs ('path/to/image?serial=1') inside templates, styles and javascripts
- Define multiple css/js packages
- Manage css/js order inside package
Simple tool, that helps you minimize your traffic, site loading time and browser image caching.
- python-scss for parsing scss.
- UgliPyJS for javascript minifications.
- Scss code errors will result into fatal error while parsing
- Add
rapeintoINSTALLED_APPS - Setup
ROOTto point to your project dir. You wouldn't like the default. - Move your scripts and styles into
RAPE_PATH. - Setup
RAPED_SCRIPTSandRAPED_STYLES - Use filters
raped_scriptandraped_styleto insert scripts and styles into django templates.
settings.py
# Path to project
ROOT = os.path.abspath(os.path.dirname(__file__) + "/..")
# Script lists under a name
RAPED_SCRIPTS = {
"foo":[
"bar",
"jebka"
]
}
# Style lists under names
RAPED_STYLES = {
"screen":[
"style1",
"style1_wide"
]
}
# Minify files. Results into generating smaller files.
RAPE_PACK = True
template.html
<html>
<head>
{% tag_script 'foo' %}
{% tag_style 'screen' %}">
...
And that's it! Rape should handle the rest of it.
If need to change scripts, styles and images on production sites, then you might want to use serial numbers.
Raising serial number will regenerate scripts and styles and also force the browser to download new file instead of reading from cache.
settings.py
RAPED_SERIAL = 2
There is one template tag for (S)CSS and JS files called raped_url. It adds current serial number to URLs.
style1.scss
...
background-image:url({% raped_url '../pixmaps/jebka.png' %});
...
Resulting into
...
background-image:url(../pixmaps/jebka.png?serial=2);
...