Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opting out of no-cache default behavior #413

Open
jasongrout opened this issue Feb 12, 2021 · 1 comment
Open

Opting out of no-cache default behavior #413

jasongrout opened this issue Feb 12, 2021 · 1 comment

Comments

@jasongrout
Copy link
Contributor

jasongrout commented Feb 12, 2021

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?

@jasongrout jasongrout changed the title Better default caching behavior Opting out of no-cache default behavior Feb 12, 2021
@jasongrout
Copy link
Contributor Author

Or perhaps it's easy for an extension to override this default caching behavior by subclassing a static file handler? If so, it would be great to have an example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants