diff --git a/IPython/html/base/handlers.py b/IPython/html/base/handlers.py index 602939245..8765c3dbe 100644 --- a/IPython/html/base/handlers.py +++ b/IPython/html/base/handlers.py @@ -129,6 +129,11 @@ class IPythonHandler(AuthenticatedHandler): # URLs #--------------------------------------------------------------- + @property + def version_hash(self): + """The version hash to use for cache hints for static files""" + return self.settings.get('version_hash', '') + @property def mathjax_url(self): return self.settings.get('mathjax_url', '') @@ -240,6 +245,7 @@ class IPythonHandler(AuthenticatedHandler): static_url=self.static_url, sys_info=sys_info, contents_js_source=self.contents_js_source, + version_hash=self.version_hash, ) def get_json_body(self): diff --git a/IPython/html/notebookapp.py b/IPython/html/notebookapp.py index 028de8b8b..7e4f48f45 100644 --- a/IPython/html/notebookapp.py +++ b/IPython/html/notebookapp.py @@ -7,6 +7,7 @@ from __future__ import print_function import base64 +import datetime import errno import io import json @@ -84,6 +85,7 @@ from IPython.utils.traitlets import ( ) from IPython.utils import py3compat from IPython.utils.path import filefind, get_ipython_dir +from IPython.utils.sysinfo import get_sys_info from .utils import url_path_join @@ -151,6 +153,15 @@ class NotebookWebApplication(web.Application): jenv_opt = jinja_env_options if jinja_env_options else {} env = Environment(loader=FileSystemLoader(template_path), **jenv_opt) + + sys_info = get_sys_info() + if sys_info['commit_source'] == 'repository': + # don't cache (rely on 304) when working from master + version_hash = '' + else: + # reset the cache on server restart + version_hash = datetime.datetime.now().strftime("%Y%m%d%H%M%S") + settings = dict( # basics log_function=log_request, @@ -160,6 +171,7 @@ class NotebookWebApplication(web.Application): static_path=ipython_app.static_file_path, static_handler_class = FileFindHandler, static_url_prefix = url_path_join(base_url,'/static/'), + version_hash=version_hash, # authentication cookie_secret=ipython_app.cookie_secret, diff --git a/IPython/html/templates/page.html b/IPython/html/templates/page.html index 6ec18f4a6..27eb2b789 100644 --- a/IPython/html/templates/page.html +++ b/IPython/html/templates/page.html @@ -18,6 +18,9 @@