Skip to content

Conversation

@anaxite
Copy link

@anaxite anaxite commented Apr 10, 2025

This PR adds extra favicons to the main astro.build site. They improve the look and feel for macOS, iOS, and Android users. Fixes #1273.

See Deeper dive below for the fun details.

Summary of changes

  • Adds favicon.ico and favicon-hidden.ico for Safari on macOS.
  • Modifies the script in Favicon.astro to work on Safari.
  • Adds apple-touch-icon.png for iOS icons.
  • Adds android-chrome-*.png icons, and a web manifest, for an improved Android experience.

The web manifest icons are optional. They can be removed from the PR.

Browser Test Checklist

I have tested this PR on at least three of the following browsers:

  • Chrome / Chromium
  • Firefox
  • Android Firefox
  • Safari
  • iOS Safari

Deeper dive

This article explains the state of favicons in 2025:

  • Safari doesn't want SVG.
  • Chrome understands SVG, but will prefer favicons declared earlier unless you add extra attributes.
  • iOS needs another icon.
  • Android can understand SVG favicons, but prefers special PNG icons declared in a manifest.

Astro.build uses a small script in Favicon.astro to change the favicon based on tab visibility. To take Safari into account we need to first do a user agent check, then modify the most relevant <link> element. But of course, querySelector('link[rel="icon"]') doesn't work the same on every browser!

  • On Firefox, querySelector('link[rel="icon"]') selects the first element that references the icon currently in use, even if the element is technically not first in the source.
  • On Chrome, querySelector('link[rel="icon"]') selects the very first link element that matches rel="icon", even if it's not currently in use.

The fix is to use querySelector() with more specificity, conditionally based on the user agent check.

If Safari starts using SVG favicons, it will make things much simpler.

anaxite added 9 commits April 10, 2025 14:18
- iOS devices
- Safari on macOS
- add `favicon.ico` declaration
- add `sizes` declaration for SVG favicon
- add apple touch icon declaration
The script in `Favicon.astro` works with SVG icons.
If we're Safari on macOS, use an .ico file instead.
Android uses these in a few places.
It's a bit of polish.
- Safari will want us to work with the first favicon element.
- Chrome needs querySelector on the second favicon element, or it doesn't work well.
@netlify
Copy link

netlify bot commented Apr 10, 2025

Deploy Preview for astro-www-2 ready!

Name Link
🔨 Latest commit 9993b5d
🔍 Latest deploy log https://app.netlify.com/sites/astro-www-2/deploys/67f80a37d184560008157b77
😎 Deploy Preview https://deploy-preview-1516--astro-www-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
5 paths audited
Performance: 97 (🔴 down 3 from production)
Accessibility: 100 (no change from production)
Best Practices: 94 (🟢 up 2 from production)
SEO: 100 (no change from production)
PWA: 90 (🟢 up 60 from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

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.

Favicon not displayed in Safari

1 participant