Skip to content

Opting out of no-cache default behavior #413

@jasongrout

Description

@jasongrout

It seems that the no-cache cache control header is set by default on files served, unless a request has a v= query parameter:

if "v" not in self.request.arguments or \
any(self.request.path.startswith(path) for path in self.no_cache_paths):
self.set_header("Cache-Control", "no-cache")

if "v" not in self.request.arguments:
self.add_header("Cache-Control", "no-cache")

This logic came from this commit in the notebook server, and seems to have been introduced for notebook 4.0:

jupyter/notebook@fe730a6

It seems that this logic is trying to make things better by default for static resources that are not cache-friendly (e.g., files that change, but retain the same name). In some ways, it is a workaround for static assets that are not cache-friendly.

In some webapps like JupyterLab, static resources are compiled to be cache friendly. For example, our static files generated from webpack contain a content hash in the filename. However, in order to enable caching of these resources, we have to use a workaround like that introduced in jupyterlab/jupyterlab#9776 to instruct webpack to append a ?v= to each request.

It seems it would be cleaner if we could opt out of the no-cache default behavior at the handler level instead of having to put in extra code to work around it at the individual request level.

Perhaps it's too much to ask for the default to be allowing caching, and those that need a default no-cache behavior at the handler level having to opt in to it?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions