Skip to content

Commit ac42f96

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

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

dash/dash.py

Lines changed: 16 additions & 4 deletions
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,21 @@ 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(os.path.join(self._assets_folder, self._favicon))
470+
favicon_url = self.get_asset_url(self._favicon) + '?m={}'.format(
471+
favicon_mod_time
472+
)
473+
else:
474+
favicon_url = '{}_favicon.ico'.format(
475+
self.config.requests_pathname_prefix)
476+
477+
favicon = _format_tag('link', {
478+
'rel': 'icon',
479+
'type': 'image/x-icon',
480+
'href': favicon_url
481+
}, opened=True)
470482

471483
index = self.interpolate_index(
472484
metas=metas, title=title, css=css, config=config,

0 commit comments

Comments
 (0)