概要
laravelはインストール時に プロジェクトルート/publicにfavicon.icoが存在する。
Faviconは<link rel="icon" href="ファイルパス" />のように指定することで指定可能である。
laravelのベースとなるbladeファイルには<link rel="icon" href="ファイルパス" />の記載がないのに用意されているfavicon.icoがFaviconとして設定されており、どういう仕組みか気になったので簡単にまとめる。
内容
laravelが用意したfavicon.icoを勝手に使っているのはブラウザ
タイトル詐欺 + 出落ち感満載だが、今回ほぼlaravelは関係なかった。
プロジェクトルート/public/favicon.icoをlink要素の指定無しに設定しているのはブラウザだった。
どうやらどのブラウザでも「link要素の指定がない場合、パブリックルートと探索しfavicon.icoというファイルがあったら勝手にFaviconに設定」するらしい。
規格で決まってるらしい
W3Cという団体がWeb技術の標準化を行っておりそこで標準化規格としてきまっているもよう。
なので「Chromeは勝手にFavicon設定してくれるけど、Safariはしてくれない」とかはない。
In the absence of a link with the icon keyword, for Document objects obtained over HTTP or HTTPS, user agents may instead run these steps in parallel:
Let request be a new request whose URL is the absolute URL obtained by resolving the URL "/favicon.ico" against the document’s URL, client is the Document object’s Window object’s environment settings object, type is "image", destination is "subresource", synchronous flag is set, credentials mode is "include", and whose use-URL-credentials flag is set.
Let response be the result of fetching request.
Use response’s unsafe response as an icon as if it had been declared using the icon keyword.
和訳↓
アイコンキーワードへのリンクが存在しない場合、HTTPまたはHTTPS経由で取得されたDocumentオブジェクトに対して、ユーザーエージェントは代わりに以下の手順を並行して実行できる:
request を新しいリクエストとし、その URL はドキュメントの URL に対して 「/favicon.ico」 を解決して得られる絶対 URL とする。client は Document オブジェクトの Window オブジェクトの環境設定オブジェクト、type は 「image」、destination は 『subresource』、同期フラグは設定済み、認証モードは 「include」、use-URL-credentials フラグは設定済みとする。
レスポンスをリクエストの取得結果とする。
レスポンスのアンセーフレスポンスを、iconキーワードで宣言されたかのようにアイコンとして使用する。
laravelが用意したFaviconから変えたい場合
- 任意のFaviconにしたい場合:
- link要素を用いて明示的に指定
-
プロジェクトルート/publicのfavicon.icoを任意のものに変更
- ブラウザデフォルトのFaviconにしたい
-
プロジェクトルート/publicのfavicon.icoを削除
-
参考文献