Skip to content

Commit

Permalink
add build time as a query parameter for scripts.js and styles.css
Browse files Browse the repository at this point in the history
This forces browsers to fetch the files again when the package has been
rebuilt.
  • Loading branch information
christianp committed Mar 20, 2024
1 parent 09a8a9c commit 8da71e4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions bin/numbas.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ def get_theme_path(self, theme):
def compile(self):
self.parse_exam()

self.build_time = datetime.datetime.now()

files = self.files = self.collect_files()

self.render_templates()
Expand Down Expand Up @@ -288,7 +290,7 @@ def render_templates(self):
def render_template(self, name):
try:
template = self.template_environment.get_template(name)
output = template.render({'exam': self.exam, 'options': self.options})
output = template.render({'exam': self.exam, 'options': self.options, 'build_time': self.build_time.timestamp()})
return output
except jinja2.exceptions.TemplateNotFound:
return None
Expand Down Expand Up @@ -441,7 +443,7 @@ def compileToZip(self):
dst = ZipInfo(str(Path(dst).relative_to('.')))
dst.compress_type = zipfile.ZIP_DEFLATED
dst.external_attr = 0o644<<16
dst.date_time = datetime.datetime.today().timetuple()
dst.date_time = self.build_time.timetuple()
if isinstance(src, Path):
f.writestr(dst, src.read_bytes())
else:
Expand Down
2 changes: 1 addition & 1 deletion themes/default/templates/scripts.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<script type="text/javascript" src="{{options.mathjax_url}}/MathJax.js?config=TeX-AMS-MML_HTMLorMML.js"></script>

<!-- numbas stuff -->
<script charset="UTF-8" type="text/javascript" src="scripts.js" charset="utf-8"></script>
<script charset="UTF-8" type="text/javascript" src="scripts.js?build_time={{build_time}}" charset="utf-8"></script>
{% if not dont_start_exam %}
<script>
Numbas.queueScript('go',['start-exam'],function() {
Expand Down
2 changes: 1 addition & 1 deletion themes/default/templates/stylesheets.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
display: none;
}
</style>
<link rel="stylesheet" type="text/css" href="styles.css" />
<link rel="stylesheet" type="text/css" href="styles.css?build_time={{build_time}}" />

0 comments on commit 8da71e4

Please sign in to comment.