Skip to content
New issue

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

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

Already on GitHub? # to your account

Add cache control header and cache busting urls to components suites. #387

Merged
merged 2 commits into from
Sep 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.26.6 - 2018-09-18
## Fixed
- Added `Cache-Control` headers to files served by `Dash.serve_components_suites`. [#387](https://github.com/plotly/dash/pull/387)
- Added time modified query string to collected components suites resources.

## 0.26.5 - 2018-09-10
## Fixed
- Fix `get_asset_url` with a different `assets_url_path`. [#374](https://github.com/plotly/dash/pull/374)
Expand Down
3 changes: 2 additions & 1 deletion dash/_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def env_configs():
'DASH_REQUESTS_PATHNAME_PREFIX',
'DASH_SUPPRESS_CALLBACK_EXCEPTIONS',
'DASH_ASSETS_EXTERNAL_PATH',
'DASH_INCLUDE_ASSETS_FILES'
'DASH_INCLUDE_ASSETS_FILES',
'DASH_COMPONENTS_CACHE_MAX_AGE'
)})


Expand Down
26 changes: 22 additions & 4 deletions dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def __init__(
external_scripts=None,
external_stylesheets=None,
suppress_callback_exceptions=None,
components_cache_max_age=None,
**kwargs):

# pylint-disable: too-many-instance-attributes
Expand Down Expand Up @@ -136,6 +137,9 @@ def __init__(
True),
'assets_external_path': _configs.get_config(
'assets_external_path', assets_external_path, env_configs, ''),
'components_cache_max_age': int(_configs.get_config(
'components_cache_max_age', components_cache_max_age,
env_configs, 2678400))
})

# list of dependencies
Expand Down Expand Up @@ -302,11 +306,18 @@ def _relative_url_path(relative_package_path='', namespace=''):
else:
self.registered_paths[namespace] = [relative_package_path]

return '{}_dash-component-suites/{}/{}?v={}'.format(
module_path = os.path.join(
os.path.dirname(sys.modules[namespace].__file__),
relative_package_path)

modified = int(os.stat(module_path).st_mtime)

return '{}_dash-component-suites/{}/{}?v={}&m={}'.format(
self.config['requests_pathname_prefix'],
namespace,
relative_package_path,
importlib.import_module(namespace).__version__
importlib.import_module(namespace).__version__,
modified
)

srcs = []
Expand Down Expand Up @@ -422,9 +433,16 @@ def serve_component_suites(self, package_name, path_in_package_dist):
'js': 'application/JavaScript',
'css': 'text/css'
})[path_in_package_dist.split('.')[-1]]

headers = {
'Cache-Control': 'public, max-age={}'.format(
self.config.components_cache_max_age)
}

return Response(
pkgutil.get_data(package_name, path_in_package_dist),
mimetype=mimetype
mimetype=mimetype,
headers=headers
)

def index(self, *args, **kwargs): # pylint: disable=unused-argument
Expand All @@ -435,7 +453,7 @@ def index(self, *args, **kwargs): # pylint: disable=unused-argument
title = getattr(self, 'title', 'Dash')
if self._favicon:
favicon = '<link rel="icon" type="image/x-icon" href="{}">'.format(
flask.url_for('assets.static', filename=self._favicon))
self.get_asset_url(self._favicon))
else:
favicon = ''

Expand Down
2 changes: 1 addition & 1 deletion dash/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.26.5'
__version__ = '0.26.6'