Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default favicon #406

Merged
merged 5 commits into from
Sep 26, 2018
Merged

Default favicon #406

merged 5 commits into from
Sep 26, 2018

Conversation

T4rk1n
Copy link
Contributor

@T4rk1n T4rk1n commented Sep 26, 2018

Adds a default favicon favicon-16x16 if no favicon is found in the assets folder.

To override the default favicon, you just need to put a favicon.ico file in the assets folder.

Resolves #152.

@T4rk1n T4rk1n requested review from rmarren1 and ned2 September 26, 2018 15:42
Copy link
Contributor

@ned2 ned2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some comments, but no real issues. Good to see this getting attended to!

💃

dash/dash.py Outdated
@@ -216,6 +216,9 @@ 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']),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this route be {}_favicon.ico? I feel like this would make it clearer that the route is serving a .ico file directly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes probably clearer thanks.

dash/dash.py Outdated
favicon = ''
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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found this logic with the nested formats and conditional expression a little hard to parse initially. I'd have a preference for something more verbose but easier to read, like:

if self._favicon:
    favicon_url = self.get_asset_url(self._favicon)
else:
    favicon_url = '{}_favicon'.format(self.config.requests_pathname_prefix)
favicon = '<link rel="icon" type="image/x-icon" href="{}">'.format(favicon_url)

@rmarren1
Copy link
Contributor

rmarren1 commented Sep 26, 2018

This looks good. I found it a bit difficult to change the favicon.ico since it is (at least for me in Chrome 69) not cleared when the cache is deleted. It seems to take hours to days for this to change in some browsers according to some posts on SO.

Do you think we can implement a cache-busting mechanism when users have custom favicon.ico files?
I was thinking of something like this:

if self._favicon:
    favicon_url = self.get_asset_url(self._favicon)
    favicon_path = os.path.join(self._assets_folder, favicon_url)
    favicon_changed_time = os.path.getmtime(favicon_path)
    favicon_url += '?v={}'.format(favicon_changed_time)
else:
    favicon_url = '{}_favicon'.format(self.config.requests_pathname_prefix)
favicon = '<link rel="icon" type="image/x-icon" href="{}">'.format(favicon_url)

This should bust the cache every time the favicon.ico file is modified. Got the idea from here

I'm 💃 with or without this change, but I think this will help save people a lot of time who can't figure out why their favicon.ico won't change.

Copy link
Contributor

@rmarren1 rmarren1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, tested it with a bunch of different favicons. Would be nice to have cache busting if it works.

@T4rk1n
Copy link
Contributor Author

T4rk1n commented Sep 26, 2018

@rmarren1 good point, I will add cache busting for the assets favicon.

@T4rk1n T4rk1n merged commit 9c00695 into master Sep 26, 2018
@T4rk1n T4rk1n deleted the default-favicon branch September 26, 2018 19:14
@T4rk1n T4rk1n mentioned this pull request Sep 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants