Skip to content

Commit 569f5bc

Browse files
committed
added URL hashing for cache busting build/*.js files
1 parent c170b2b commit 569f5bc

16 files changed

+44
-15
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# add cache-busting query strings for build/*.js files referenced by all html
2+
# files in the current directory
3+
4+
import os, re, hashlib
5+
6+
PREFIX = 'src="'
7+
SUFFIX = '"'
8+
9+
STUFF_RE = re.compile(PREFIX + '(build/.*[.]js).*?' + SUFFIX)
10+
11+
for f in os.listdir('.'):
12+
if f.endswith('.html'):
13+
#print f
14+
new_f = f + '.NEW'
15+
with open(new_f, 'w') as out:
16+
for line in open(f):
17+
m = STUFF_RE.search(line)
18+
if m:
19+
js_filename = m.group(1)
20+
assert os.path.isfile(js_filename)
21+
md5_hash = hashlib.md5(open(js_filename, 'rb').read()).hexdigest()
22+
md5_hash = md5_hash[:10] # truncate to prettify
23+
modified_line = re.sub(STUFF_RE, 'src="' + js_filename + '?' + md5_hash + SUFFIX, line)
24+
#print modified_line
25+
out.write(modified_line)
26+
else:
27+
out.write(line)
28+
29+
os.rename(new_f, f)

v5-unity/c.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<!-- let Webpack take care of everything. Use the [hash] feature to
2121
create unique filenames for releases:
2222
https://webpack.github.io/docs/long-term-caching.html -->
23-
<script type="text/javascript" src="build/visualize.bundle.js" charset="utf-8"></script>
23+
<script type="text/javascript" src="build/visualize.bundle.js?d8b71492be" charset="utf-8"></script>
2424

2525
<!-- insert google-analytics.txt contents here -->
2626

v5-unity/composingprograms.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<title>Online Python Tutor - Composing Programs - Python 3</title>
1212

1313
<meta http-equiv="Content-type" content="text/html; charset=UTF-8"/>
14-
<script type="text/javascript" src="build/composingprograms.bundle.js" charset="utf-8"></script>
14+
<script type="text/javascript" src="build/composingprograms.bundle.js?0553452044" charset="utf-8"></script>
1515

1616
<!-- insert google-analytics.txt contents here -->
1717

v5-unity/cpp.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<!-- let Webpack take care of everything. Use the [hash] feature to
2121
create unique filenames for releases:
2222
https://webpack.github.io/docs/long-term-caching.html -->
23-
<script type="text/javascript" src="build/visualize.bundle.js" charset="utf-8"></script>
23+
<script type="text/javascript" src="build/visualize.bundle.js?d8b71492be" charset="utf-8"></script>
2424

2525
<!-- insert google-analytics.txt contents here -->
2626

v5-unity/csc108h.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<title>Online Python Tutor - csc108h</title>
1212

1313
<meta http-equiv="Content-type" content="text/html; charset=UTF-8"/>
14-
<script type="text/javascript" src="build/csc108h.bundle.js" charset="utf-8"></script>
14+
<script type="text/javascript" src="build/csc108h.bundle.js?a124adb84a" charset="utf-8"></script>
1515

1616
<!-- insert google-analytics.txt contents here -->
1717

v5-unity/csc108h_shared.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<title>Online Python Tutor - csc108h with shared sessions</title>
1212

1313
<meta http-equiv="Content-type" content="text/html; charset=UTF-8"/>
14-
<script type="text/javascript" src="build/csc108h.bundle.js" charset="utf-8"></script>
14+
<script type="text/javascript" src="build/csc108h.bundle.js?a124adb84a" charset="utf-8"></script>
1515

1616
<!-- insert google-analytics.txt contents here -->
1717

v5-unity/embedding-demo.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<title>Online Python Tutor embedding demo</title>
1212

1313
<!-- let Webpack take care of everything -->
14-
<script type="text/javascript" src="build/embedding-demo.bundle.js" charset="utf-8"></script>
14+
<script type="text/javascript" src="build/embedding-demo.bundle.js?a266c0dd6b" charset="utf-8"></script>
1515

1616
</head>
1717

v5-unity/iframe-embed.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<!-- let Webpack take care of everything. Use the [hash] feature to
88
create unique filenames for releases:
99
https://webpack.github.io/docs/long-term-caching.html -->
10-
<script type="text/javascript" src="build/iframe-embed.bundle.js" charset="utf-8"></script>
10+
<script type="text/javascript" src="build/iframe-embed.bundle.js?862caec3c5" charset="utf-8"></script>
1111

1212
</head>
1313

v5-unity/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<meta http-equiv="Content-type" content="text/html; charset=UTF-8"/>
1515

1616
<!-- let Webpack take care of everything -->
17-
<script type="text/javascript" src="build/index.bundle.js" charset="utf-8"></script>
17+
<script type="text/javascript" src="build/index.bundle.js?e20ffa39bc" charset="utf-8"></script>
1818

1919
<!-- insert google-analytics.txt contents here -->
2020

v5-unity/java.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<!-- let Webpack take care of everything. Use the [hash] feature to
2121
create unique filenames for releases:
2222
https://webpack.github.io/docs/long-term-caching.html -->
23-
<script type="text/javascript" src="build/visualize.bundle.js" charset="utf-8"></script>
23+
<script type="text/javascript" src="build/visualize.bundle.js?d8b71492be" charset="utf-8"></script>
2424

2525
<!-- insert google-analytics.txt contents here -->
2626

0 commit comments

Comments
 (0)