0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

laravel 明示的にFaviconを指定しなくてもパブリックルートのfavicon.icoが設定される

0
Last updated at Posted at 2025-11-30

概要

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を削除

参考文献

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?