INTRO
* INSTALL assetpackager on your django project
* http://django-assetpackager.googlecode.com
* tested with Python2.5.1, trunk of app revision 6 and Django 7476
INSTALL
1. place 'assetpackager' app in your django project (i.e. myproject):
myproject ~# svn checkout http://django-assetpackager.googlecode.com/svn/trunk/assetpackager assetpackager
or add on your svn external tree if you use svn control system:
myproject ~# svn propedit svn:externals .
# and add this line
myproject/assetpackager -r6 http://django-assetpackager.googlecode.com/svn/trunk/assetpackager
# and
myproject ~# svn up
2. tested with revision 6, need to be patched (fixes):
myproject ~# cat assetpackager-rev-6-fix.patch | patch -Np0
notice: this patch also fully comment 'Site' usage
3. enable application on your project:
# add to your settings.py file
INSTALLED_APPS = (
...
'myproject.assetpackager',
)
4. create db new structure tables
myproject ~# python manage.py syncdb
5. go to django admin interface (need to be enable) and add your JS and CSS files
6. call
tenplatetages on your template:
{% load asset_include %}
or to auto load on all templates:
# add to __init__.py of your project
from django import template
template.add_to_builtins("myproject.assetpackager.templatetags.asset_include")
7. now on your template, example base.html add:
<head>
# for calling all files imported
{% javascript_include_merged :base %}
# or call each desired file individualy
{% javascript_include_merged jquery-1.2.3.js jquery.cookie.js ...etc... myproject.js %}
for CSS files item with:
# for calling all files imported
{% css_include_merged :base %}
# or call each desired file individualy
{% css_include_merged reset.css layout.js style.css ...etc... myproject.css %}
</head>
Result, all files or selected are merged to settings.MEDIA_ROOT+"js/base.js"
and after minifyed to settings.MEDIA_ROOT+"js/base_<timestamp>.<id>.js", this technique
force browser like ie5/6 to load last js/css change. Item process for CSS files.
Principe: the files are re-minified only when files are modified (sha.hexdigest hash control)
Now if your settings.DEBUG = False
your JS and/or CSS files will be minified.
Temptatetages output is like that:
<script type="text/javascript" src="/media/js/base_1211045107.0.js"></script>
otherwise switch to individual:
<script type="text/javascript" src="/media/js/jquery-1.2.3.js" charset="utf-8"></script>
<script type="text/javascript" src="/media/js/jquery.cookie.js" charset="utf-8"></script>
...
<script type="text/javascript" src="/media/js/myproject.js" charset="utf-8"></script>
Item for CSS files.
Thanks, to author of
django-assetpackager, Dj Gilcrease
Mathieu Meylan, May 17 2008