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

docs: Oryx favicons #2443

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions _data/sidebars/scos_dev_sidebar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1655,6 +1655,8 @@ entries:
include_versions:
- "202307.0"
- "202311.0"
- title: Favicon and PWA icons
url: /docs/scos/dev/front-end-development/oryx/building-applications/styling/oryx-favicon.html

- title: Building pages
nested:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
title: "Oryx: Favicons"
description:
last_updated: January 11, 2024
template: concept-topic-template
---

Favicons, short for "favorite icons", are small, iconic images that represent a website or web application. They are typically displayed in the browser's address bar, tabs, and bookmarks. Creating a favicon involves designing an image that effectively conveys the identity of the web application in a small, recognizable format. Most brands use their logo or a variation of the logo in the favicon. The challenging part is often the limited available size.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd say there is near zero sense to explain what is favicon in frontend framework documentation :) So I'd shorten this section.


## Technical format
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe Icon/Image format?


(Fav)icons can be created in different technical formats, such as `png`, `ico`, `gif` or `svg`. It is recommended to create a favicon in SVG format. SVG based favicons tend to be lighter in file size and can be used for different sizes. SVG can also natively manage light and dark mode variations.

The various demo applications that are provided use the Spryker logo as a reference favicon. The logo is provided in the resource package as an SVG icon and supports dark and light mode as part of the SVG:

```html
<svg xmlns="http://www.w3.org/2000/svg">
<style>
@media (prefers-color-scheme: light) {
g {
fill: var(--oryx-fill, currentcolor);
}
}
@media (prefers-color-scheme: dark) {
g {
fill: var(--oryx-fill, white);
}
}
</style>
<g>
...
</g>
</svg>
```

The logo is referenced from a file. While favicons can be rendered inline in the meta data, as a base64 SVG, it is only recommended for a simple vector shape. Most logos will generate a large string in base64 and increases every (SSR rendered) page significantly. In case of a dark mode variation, it will be even worse. Moreover, a base64 based favicon cannot be cached and reused.
Copy link
Collaborator

Choose a reason for hiding this comment

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

In case of a dark mode variation, it will be even worse.

Maybe explanation why it will be even worse would be good.

Copy link
Collaborator

Choose a reason for hiding this comment

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

What do you about adding an example of logo in base64 format? So we have an example for each case.


## Meta tags

Favicons can be added to a web page in different ways. Oryx prefers to add them in the header of the html. While dark mode is supported inline in the SVG, somehow browsers won't automatically rerender the favicon when the device color mode is changing. Therefore, the favicon is added twice in the html. This will cause a correct rerendering of the light vs dark mode favicon.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Favicons can be added to a web page in different ways. Oryx prefers to add them in the header of the html. While dark mode is supported inline in the SVG, somehow browsers won't automatically rerender the favicon when the device color mode is changing. Therefore, the favicon is added twice in the html. This will cause a correct rerendering of the light vs dark mode favicon.
Favicons can be added to a web page in different ways. Oryx prefers to add them in the head of the html document. While dark mode is supported inline in the SVG, somehow browsers won't automatically rerender the favicon when the device color mode is changing. Therefore, the favicon is added twice in the html. This will cause a correct rerendering of the light vs dark mode favicon.


```html
<link rel="icon" href="/public/logo.svg">
<link rel="icon" href="/public/logo.svg" media="(prefers-color-scheme: dark)">
```
Comment on lines +42 to +45
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
```html
<link rel="icon" href="/public/logo.svg">
<link rel="icon" href="/public/logo.svg" media="(prefers-color-scheme: dark)">
```
```html
<head>
...
<link rel="icon" href="/public/logo.svg">
<link rel="icon" href="/public/logo.svg" media="(prefers-color-scheme: dark)">
...
</head>


Given that the same SVG is referenced, there's no overhead on downloading the file twice.

### Provide your custom favicons

The [boilerplate](/docs/scos/dev/front-end-development/{{page.version}}/oryx/getting-started/oryx-boilerplate.html) of Oryx is very light and does not have hardcoded meta tags in the index.html. The icons are added through the `StorefrontMetaInitializer`, which you can override when needed.

Oryx provides a `StorefrontMetaInitializer` that is used to add global elements to the page header, such as a link to a font, body styles and meta tags. The meta tags include the logo icon.

You can add custom elements to the page by overriding the meta service:

```ts
import { StorefrontMetaInitializer, ElementDefinition } from '@spryker-oryx/presets';

export class CustomStorefrontMetaInitializer extends StorefrontMetaInitializer {

initialize(): void {
super.initialize();
this.metaService?.add(
// array with custom element definitions (ElementDefinition)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe let's add a real example?

);
}
}
```
The `PageMetaService` is used for both global meta definitions as well as individual pages such as a meta tags (e.g. robots) or links (e.g. canonical URL).

You can of course neglect the page service implementation and add the meta tags in your custom index.html file. The main reason for Oryx to not do this, is that favicons, like anything in Oryx, can be provided dynamically. Favicons could be data driven, e.g. different per brand.
Loading