Skip to content

Commit d2a2752

Browse files
committed
Add assets favicon cache busting, clearer favicon tag format.
1 parent 11905d8 commit d2a2752

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

dash/dash.py

+17-4
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def add_url(name, view_func, methods=('GET',)):
216216
'{}<path:path>'.format(self.config['routes_pathname_prefix']),
217217
self.index)
218218

219-
add_url('{}_favicon'.format(self.config['routes_pathname_prefix']),
219+
add_url('{}_favicon.ico'.format(self.config['routes_pathname_prefix']),
220220
self._serve_default_favicon)
221221

222222
self.server.before_first_request(self._setup_server)
@@ -464,9 +464,22 @@ def index(self, *args, **kwargs): # pylint: disable=unused-argument
464464
config = self._generate_config_html()
465465
metas = self._generate_meta_html()
466466
title = getattr(self, 'title', 'Dash')
467-
favicon = '<link rel="icon" type="image/x-icon" href="{}">'.format(
468-
self.get_asset_url(self._favicon) if self._favicon
469-
else '{}_favicon'.format(self.config.requests_pathname_prefix))
467+
468+
if self._favicon:
469+
favicon_mod_time = os.path.getmtime(
470+
os.path.join(self._assets_folder, self._favicon))
471+
favicon_url = self.get_asset_url(self._favicon) + '?m={}'.format(
472+
favicon_mod_time
473+
)
474+
else:
475+
favicon_url = '{}_favicon.ico'.format(
476+
self.config.requests_pathname_prefix)
477+
478+
favicon = _format_tag('link', {
479+
'rel': 'icon',
480+
'type': 'image/x-icon',
481+
'href': favicon_url
482+
}, opened=True)
470483

471484
index = self.interpolate_index(
472485
metas=metas, title=title, css=css, config=config,

0 commit comments

Comments
 (0)