Skip to content

Commit

Permalink
Add fingerprinting to favicons to bust browser caching (#823)
Browse files Browse the repository at this point in the history
  • Loading branch information
devneill authored Aug 26, 2024
1 parent bd837f4 commit 7a6c064
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 11 deletions.
File renamed without changes
File renamed without changes
13 changes: 7 additions & 6 deletions app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import {
import { withSentry } from '@sentry/remix'
import { useRef } from 'react'
import { HoneypotProvider } from 'remix-utils/honeypot/react'
import appleTouchIconAssetUrl from './assets/favicons/apple-touch-icon.png'
import faviconAssetUrl from './assets/favicons/favicon.svg'
import { GeneralErrorBoundary } from './components/error-boundary.tsx'
import { EpicProgress } from './components/progress-bar.tsx'
import { SearchBar } from './components/search-bar.tsx'
Expand Down Expand Up @@ -52,19 +54,18 @@ export const links: LinksFunction = () => {
return [
// Preload svg sprite as a resource to avoid render blocking
{ rel: 'preload', href: iconsHref, as: 'image' },
{ rel: 'mask-icon', href: '/favicons/mask-icon.svg' },
{
rel: 'alternate icon',
type: 'image/png',
href: '/favicons/favicon-32x32.png',
rel: 'icon',
href: '/favicon.ico',
sizes: '48x48',
},
{ rel: 'apple-touch-icon', href: '/favicons/apple-touch-icon.png' },
{ rel: 'icon', type: 'image/svg+xml', href: faviconAssetUrl },
{ rel: 'apple-touch-icon', href: appleTouchIconAssetUrl },
{
rel: 'manifest',
href: '/site.webmanifest',
crossOrigin: 'use-credentials',
} as const, // necessary to make typescript happy
{ rel: 'icon', type: 'image/svg+xml', href: '/favicons/favicon.svg' },
{ rel: 'stylesheet', href: tailwindStyleSheetUrl },
].filter(Boolean)
}
Expand Down
7 changes: 4 additions & 3 deletions public/favicons/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Favicon

This directory has a few versions of icons to account for different devices. In
some cases, we cannot reliably detect light/dark mode preference. Hence some of
the icons in here should not have a transparent background. These icons are
This directory has the icons used for android devices. In
some cases, we cannot reliably detect light/dark mode preference. Hence these icons should not have a transparent background. These icons are
referenced in the `site.webmanifest` file.

The icons used by modern browsers and Apple devices are in `app/assets/favicons` as they can be imported with a fingerprint to bust the browser cache.

Note, there's also a `favicon.ico` in the root of `/public` which some older
browsers will request automatically. This is a fallback for those browsers.
Binary file removed public/favicons/favicon-16x16.png
Binary file not shown.
Binary file removed public/favicons/favicon-32x32.png
Binary file not shown.
1 change: 0 additions & 1 deletion public/favicons/mask-icon.svg

This file was deleted.

6 changes: 5 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ export default defineConfig({
},

assetsInlineLimit: (source: string) => {
if (source.endsWith('sprite.svg')) {
if (
source.endsWith('sprite.svg') ||
source.endsWith('favicon.svg') ||
source.endsWith('apple-touch-icon.png')
) {
return false
}
},
Expand Down

0 comments on commit 7a6c064

Please sign in to comment.