Skip to content

Commit

Permalink
Append modified time query string to assets files.
Browse files Browse the repository at this point in the history
  • Loading branch information
T4rk1n committed Jul 31, 2018
1 parent 54ca4a3 commit 35a4bb0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
14 changes: 9 additions & 5 deletions dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,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 @@ -725,8 +726,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 @@ -749,10 +750,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

0 comments on commit 35a4bb0

Please sign in to comment.