|
3 | 3 | # Copyright (c) Jupyter Development Team.
|
4 | 4 | # Distributed under the terms of the Modified BSD License.
|
5 | 5 |
|
| 6 | +from glob import glob |
| 7 | +from os.path import relpath |
| 8 | + |
6 | 9 | from jupyter_server.extension.application import ExtensionApp, ExtensionAppJinjaMixin
|
| 10 | +from jupyter_server.utils import url_path_join as ujoin |
7 | 11 | from traitlets import Dict, Integer, Unicode, observe
|
8 | 12 |
|
9 | 13 | from ._version import __version__
|
@@ -97,6 +101,27 @@ def _deprecated_trait(self, change):
|
97 | 101 | )
|
98 | 102 | setattr(self, new_attr, change.new)
|
99 | 103 |
|
| 104 | + def initialize_settings(self): |
| 105 | + """Initialize the settings: |
| 106 | +
|
| 107 | + set the static files as immutable, since they should have all hashed name. |
| 108 | + """ |
| 109 | + immutable_cache = set(self.settings.get("static_immutable_cache", [])) |
| 110 | + |
| 111 | + # Set lab static files as immutables |
| 112 | + immutable_cache.add(self.static_url_prefix) |
| 113 | + |
| 114 | + # Set extensions static files as immutables |
| 115 | + for extension_path in self.labextensions_path + self.extra_labextensions_path: |
| 116 | + extensions_url = [ |
| 117 | + ujoin(self.labextensions_url, relpath(path, extension_path)) |
| 118 | + for path in glob(f'{extension_path}/**/static', recursive=True) |
| 119 | + ] |
| 120 | + |
| 121 | + immutable_cache.update(extensions_url) |
| 122 | + |
| 123 | + self.settings.update({"static_immutable_cache": list(immutable_cache)}) |
| 124 | + |
100 | 125 | def initialize_templates(self):
|
101 | 126 | """Initialize templates."""
|
102 | 127 | self.static_paths = [self.static_dir]
|
|
0 commit comments