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

Bust the assets cache on modification. #309

Merged
merged 2 commits into from
Aug 10, 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.24.0 - 2018-08-10
## Added
- Add a modified time query string to the assets included in the index in order to bust the cache. [#319](https://github.com/plotly/dash/pull/309)

## 0.23.1 - 2018-08-02
## Added
- Add ie-compat meta tag to the index by default. [#316](https://github.com/plotly/dash/pull/316)
Expand Down
14 changes: 9 additions & 5 deletions dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ def _relative_url_path(relative_package_path='', namespace=''):
)
elif 'asset_path' in resource:
static_url = flask.url_for('assets.static',
filename=resource['asset_path'])
filename=resource['asset_path'],
mod=resource['ts'])
srcs.append(static_url)
return srcs

Expand Down Expand Up @@ -863,8 +864,8 @@ def _walk_assets_directory(self):
walk_dir = self._assets_folder
slash_splitter = re.compile(r'[\\/]+')

def add_resource(p):
res = {'asset_path': p}
def add_resource(p, filepath):
res = {'asset_path': p, 'filepath': filepath}
if self.config.assets_external_path:
res['external_url'] = '{}{}'.format(
self.config.assets_external_path, path)
Expand All @@ -887,10 +888,13 @@ def add_resource(p):
else:
path = f

full = os.path.join(current, f)

if f.endswith('js'):
self.scripts.append_script(add_resource(path))
self.scripts.append_script(
add_resource(path, full))
elif f.endswith('css'):
self.css.append_css(add_resource(path))
self.css.append_css(add_resource(path, full))
elif f == 'favicon.ico':
self._favicon = path

Expand Down
3 changes: 3 additions & 0 deletions dash/resources.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from copy import copy
import json
import warnings
import os

from .development.base_component import Component

Expand Down Expand Up @@ -30,7 +31,9 @@ def _filter_resources(self, all_resources):
elif 'absolute_path' in s:
filtered_resource['absolute_path'] = s['absolute_path']
elif 'asset_path' in s:
info = os.stat(s['filepath'])
filtered_resource['asset_path'] = s['asset_path']
filtered_resource['ts'] = info.st_mtime
elif self.config.serve_locally:
warnings.warn(
'A local version of {} is not available'.format(
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.23.1'
__version__ = '0.24.0'