don't cache files in static/custom or nbextensions

always rely on 304 for cache content there
This commit is contained in:
Min RK 2014-11-24 21:12:55 -08:00
parent a492ac554d
commit 3cf5262b0c
2 changed files with 16 additions and 5 deletions

View File

@ -320,7 +320,7 @@ class AuthenticatedFileHandler(IPythonHandler, web.StaticFileHandler):
def set_headers(self):
super(AuthenticatedFileHandler, self).set_headers()
# disable browser caching, rely in 304 replies for savings
# disable browser caching, rely on 304 replies for savings
if "v" not in self.request.arguments:
self.add_header("Cache-Control", "no-cache")
@ -394,11 +394,14 @@ class FileFindHandler(web.StaticFileHandler):
def set_headers(self):
super(FileFindHandler, self).set_headers()
# disable browser caching, rely in 304 replies for savings
if "v" not in self.request.arguments:
# disable browser caching, rely on 304 replies for savings
if "v" not in self.request.arguments or \
any(self.request.path.startswith(path) for path in self.no_cache_paths):
self.add_header("Cache-Control", "no-cache")
def initialize(self, path, default_filename=None):
def initialize(self, path, default_filename=None, no_cache_paths=None):
self.no_cache_paths = no_cache_paths or []
if isinstance(path, string_types):
path = [path]

View File

@ -171,6 +171,10 @@ class NotebookWebApplication(web.Application):
static_path=ipython_app.static_file_path,
static_handler_class = FileFindHandler,
static_url_prefix = url_path_join(base_url,'/static/'),
static_handler_args = {
# don't cache custom.js
'no_cache_paths': [url_path_join(base_url, 'static', 'custom')],
},
version_hash=version_hash,
# authentication
@ -218,8 +222,12 @@ class NotebookWebApplication(web.Application):
handlers.extend(load_handlers('services.sessions.handlers'))
handlers.extend(load_handlers('services.nbconvert.handlers'))
handlers.extend(load_handlers('services.kernelspecs.handlers'))
handlers.append(
(r"/nbextensions/(.*)", FileFindHandler, {'path' : settings['nbextensions_path']}),
(r"/nbextensions/(.*)", FileFindHandler, {
'path': settings['nbextensions_path'],
'no_cache_paths': ['/'], # don't cache anything in nbextensions
}),
)
# register base handlers last
handlers.extend(load_handlers('base.handlers'))