Skip to content

Commit

Permalink
Add assets favicon cache busting, clearer favicon tag format.
Browse files Browse the repository at this point in the history
  • Loading branch information
T4rk1n committed Sep 26, 2018
1 parent 11905d8 commit d2a2752
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def add_url(name, view_func, methods=('GET',)):
'{}<path:path>'.format(self.config['routes_pathname_prefix']),
self.index)

add_url('{}_favicon'.format(self.config['routes_pathname_prefix']),
add_url('{}_favicon.ico'.format(self.config['routes_pathname_prefix']),
self._serve_default_favicon)

self.server.before_first_request(self._setup_server)
Expand Down Expand Up @@ -464,9 +464,22 @@ def index(self, *args, **kwargs): # pylint: disable=unused-argument
config = self._generate_config_html()
metas = self._generate_meta_html()
title = getattr(self, 'title', 'Dash')
favicon = '<link rel="icon" type="image/x-icon" href="{}">'.format(
self.get_asset_url(self._favicon) if self._favicon
else '{}_favicon'.format(self.config.requests_pathname_prefix))

if self._favicon:
favicon_mod_time = os.path.getmtime(
os.path.join(self._assets_folder, self._favicon))
favicon_url = self.get_asset_url(self._favicon) + '?m={}'.format(
favicon_mod_time
)
else:
favicon_url = '{}_favicon.ico'.format(
self.config.requests_pathname_prefix)

favicon = _format_tag('link', {
'rel': 'icon',
'type': 'image/x-icon',
'href': favicon_url
}, opened=True)

index = self.interpolate_index(
metas=metas, title=title, css=css, config=config,
Expand Down

0 comments on commit d2a2752

Please sign in to comment.