Skip to content

Commit

Permalink
Merge pull request #309 from plotly/dev-mode-disable-cache
Browse files Browse the repository at this point in the history
Bust the assets cache on modification.
  • Loading branch information
T4rk1n committed Aug 10, 2018
2 parents cc0599b + 67f8601 commit 7d847c6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
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'

0 comments on commit 7d847c6

Please sign in to comment.