Permalink
Browse files

Improved CSS versioning. Now uses a filter to generate a hash queryst…

…ring and append it to the file path. This means the client only downloads the new style when it changes.
  • Loading branch information...
1 parent f1c8e45 commit 8c2b6ee59d27b9bcb3ede642c283379eecd8bbbd @lukeman lukeman committed Nov 29, 2008
Showing with 16 additions and 2 deletions.
  1. +14 −1 aym_tags/templatetags/aym.py
  2. +2 −1 templates/base.html
@@ -1,6 +1,8 @@
from django import template
from django.utils import safestring
+import md5
+
try:
import markdown
except ImportError:
@@ -59,4 +61,15 @@ def render(self, context):
h = pygments.highlight(output, lexer, formatter)
return safestring.mark_safe(h)
-
+
+@register.filter
+def md5_querystring(value, arg=None):
+ '''filter that appends a path with an md5 querystring'''
+ try:
+ f = file(value, 'r')
+ except IOError:
+ print "Couldn't find path to generate hash querystring for %s" % value
+ return value
+
+ m = md5.new(f.read()).hexdigest()
+ return "%s?%s" % (value, m)
View
@@ -1,8 +1,9 @@
+{% load aym %}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>{% block title %}My CMS{% endblock %}</title>
-<link rel="stylesheet" href="static/style.css?{% now "sdyGim" %}">
+<link rel="stylesheet" href="{{ "static/style.css"|md5_querystring }}">
<link rel="stylesheet" href="static/pygments.css">
</head>
<body>

0 comments on commit 8c2b6ee

Please sign in to comment.