Skip to content

Commit 57361ad

Browse files
authored
Implement cache busting for our own static files (#23)
Browsers cache static files. That's obviously good. Currently it results in our we change files server side, users don't always see them. This generates a GET parameter that's unique per startup of the python process to bust the cache of the client, so that it pulls in possibly updated JS/CSS files. Obviously this is a bit more often than necessary, but caching should still work most of the time and our custom css and js files are tiny anyway. At least the changes that are made will now be reflected to our users.
1 parent 9dfa825 commit 57361ad

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

pgcommitfest/commitfest/templates/base.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<link rel="stylesheet" href="/media/commitfest/css/jquery-ui.css" type="text/css">
77
<link rel="stylesheet" href="/media/commitfest/css/bootstrap.css" />
88
<link rel="stylesheet" href="/media/commitfest/css/bootstrap-theme.min.css" />
9-
<link rel="stylesheet" href="/media/commitfest/css/commitfest.css" />
9+
<link rel="stylesheet" href="/media/commitfest/css/commitfest.css?{% static_file_param %}" />
1010
<link rel="shortcut icon" href="/media/commitfest/favicon.ico" />
1111
{%block extrahead%}{%endblock%}
1212
{%if rss_alternate%} <link rel="alternate" type="application/rss+xml" title="{{rss_alternate_title}}" href="{{rss_alternate}}" />{%endif%}
@@ -43,6 +43,6 @@ <h1>{{title}}</h1>
4343
<script src="/media/commitfest/js/jquery.js"></script>
4444
<script src="/media/commitfest/js/jquery-ui.js"></script>
4545
<script src="/media/commitfest/js/bootstrap.js"></script>
46-
<script src="/media/commitfest/js/commitfest.js"></script>
46+
<script src="/media/commitfest/js/commitfest.js?{% static_file_param %}"></script>
4747
{%block morescript%}{%endblock%}
4848
</html>

pgcommitfest/commitfest/templatetags/commitfest.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from django.template.defaultfilters import stringfilter
22
from django import template
3+
from uuid import uuid4
34

45
from pgcommitfest.commitfest.models import PatchOnCommitFest
56

@@ -43,6 +44,18 @@ def alertmap(value):
4344
return 'alert-info'
4445

4546

47+
# Generate a GET parameter that's unique per startup of the python process to
48+
# bust the cache of the client, so that it pulls in possibly updated JS/CSS
49+
# files.
50+
STATIC_FILE_PARAM = f"v={uuid4()}"
51+
52+
53+
# This GET parameter should be added to every one of our static files.
54+
@register.simple_tag
55+
def static_file_param():
56+
return STATIC_FILE_PARAM
57+
58+
4659
@register.filter(name='hidemail')
4760
@stringfilter
4861
def hidemail(value):

0 commit comments

Comments
 (0)