mirror of
https://github.com/jupyter/notebook.git
synced 2025-03-19 13:20:36 +08:00
add '?v=<date>' to require URLs
- resets cache on server restart - don't cache requests on master (rely on 304 for content caching)
This commit is contained in:
parent
fe730a60c2
commit
a492ac554d
@ -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):
|
||||
|
@ -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,
|
||||
|
@ -18,6 +18,9 @@
|
||||
<script src="{{static_url("components/requirejs/require.js") }}" type="text/javascript" charset="utf-8"></script>
|
||||
<script>
|
||||
require.config({
|
||||
{% if version_hash %}
|
||||
urlArgs: "v={{version_hash}}",
|
||||
{% endif %}
|
||||
baseUrl: '{{static_url("", include_version=False)}}',
|
||||
paths: {
|
||||
nbextensions : '{{ base_url }}nbextensions',
|
||||
|
Loading…
x
Reference in New Issue
Block a user