Answers.Body: <p>By default browsers look for a favicon at the root of your web directory. So if you do not add a link in your head section, but you have a favicon.ico at webroot, you will still see it.</p>
  
  <p>However, a favicon can technically be located anywhere. If you have a multi-site installation you can reference it like this (note that you should always use a fully qualified URL or you may run into issues with IE):</p>
  
  <pre><code>&lt;link rel="shortcut icon" href="https://yourbucket.s3.amazonaws.com/{{currentSite.handle}}/favicons/favicon.ico" type="image/x-icon"&gt;
  </code></pre>
  
  <p>Insert Craft's current site handle tag so that you can use the same code on all sites. Then you'll just need to create a paths in your S3 bucket to match.</p>
  
  <p>Regarding multiple sizes, you should include more than just a 16x16 favicon. This is what I have which is all related to icon display:</p>
  
  <pre><code>&lt;link rel="shortcut icon" href="favicon.ico" type="image/x-icon"&gt;
  &lt;link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"&gt;
  &lt;link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png"&gt;
  &lt;link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png"&gt;
  &lt;link rel="manifest" href="/site.webmanifest"&gt;
  &lt;link rel="mask-icon" href="/safari-pinned-tab.svg" color="#888888"&gt;
  &lt;meta name="msapplication-TileColor" content="#ffc40d"&gt;
  &lt;meta name="theme-color" content="#ffffff"&gt;
  </code></pre>
  
  <p>The manifest, mask-icon, msapplication-TileColor, and theme-color all refer to how your favicon will appear on platforms including Safari, Windows and Android devices.</p>
  
  <p>You could add an image transform to your asset volume which creates each of the required sizes, or you could direct your client to upload multiple sizes. It may be easier to send them to <a href="https://realfavicongenerator.net/" rel="nofollow noreferrer">this site</a> to generate favicons which they can then upload to their assets volume.</p>
  
  <p>Disclaimer, I have no affiliation to the Favicon Generator site -- I just use it frequently. I generated the code you see above using this tool. If you're looking for a reliable way to generate your favicon size variations and the associated code, this online tool does the trick.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-03T04:09:28.423Z
Answers.LastActivityDate: 2019-01-03T04:20:24.057Z
Answers.LastEditDate: 2019-01-03T04:20:24.057Z
Answers.UserDisplayName: Vaughn D. Taylor
Body: <p>I have a multi-site Craft install.  I'd like to offer the ability for each site to upload an icon that will be used for favicons.  I noticed a lot of 404s for both /favicon.ico and /apple-touch-icon.png, which appear to be hardcoded in various clients.  I'd thus like to route those URLs directly to the requisite asset files, but on a per-site basis.</p>
  
  <ul>
  <li>I can't just put the files into /web, since that's shared among all the sites, and I want site-specific icons.</li>
  <li>I'm hosting assets on S3 (since we are using a load balancer).</li>
  </ul>
  
  <p><strong>Is there a way to do this in Craft without writing a custom plugin to do so?</strong></p>
  
  <p><strong>If there exists a plugin to do this, or if I could do it via Craft directly, that would be wonderful, but I cannot find a way to do so.</strong></p>
  
  <p>If I have to write a custom plugin, I'd have it basically:</p>
  
  <ul>
  <li>Respond to those URLs</li>
  <li>Look up the requisite field in Globals for the assets on a per-site basis.</li>
  <li>Download the asset file locally (and cache locally in /storage)</li>
  <li>Set the proper MIME type</li>
  <li>Serve the file from /storage directly</li>
  </ul>
  
  <p>Does this sound reasonable or would there be a better way to handle this?</p>
  
  <p>Thanks in advance for any assistance!</p>
  
Tags: <plugin-development><craft3><assets><plugins><routing>
Title: Route directly to an S3-hosted asset?
ThreadText: # Route directly to an S3-hosted asset?
  
  (Asked by: username_0 on 2019-01-02)
  
  I have a multi-site Craft install. I'd like to offer the ability for each site to upload an icon that will be used for favicons. I noticed a lot of 404s for both /favicon.ico and /apple-touch-icon.png, which appear to be hardcoded in various clients. I'd thus like to route those URLs directly to the requisite asset files, but on a per-site basis.
  
  * I can't just put the files into /web, since that's shared among all the sites, and I want site-specific icons.
  * I'm hosting assets on S3 (since we are using a load balancer).
  
  **Is there a way to do this in Craft without writing a custom plugin to do so?**
  
  **If there exists a plugin to do this, or if I could do it via Craft directly, that would be wonderful, but I cannot find a way to do so.**
  
  If I have to write a custom plugin, I'd have it basically:
  
  * Respond to those URLs
  * Look up the requisite field in Globals for the assets on a per-site basis.
  * Download the asset file locally (and cache locally in /storage)
  * Set the proper MIME type
  * Serve the file from /storage directly
  
  Does this sound reasonable or would there be a better way to handle this?
  
  Thanks in advance for any assistance!
  
  **Tags:** plugin-development, craft3, assets, plugins, routing
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-01-03. Score: 1
  
  By default browsers look for a favicon at the root of your web directory. So if you do not add a link in your head section, but you have a favicon.ico at webroot, you will still see it.
  
  However, a favicon can technically be located anywhere. If you have a multi-site installation you can reference it like this (note that you should always use a fully qualified URL or you may run into issues with IE):
  
  ```
  <link rel="shortcut icon" href="https://yourbucket.s3.amazonaws.com/{{currentSite.handle}}/favicons/favicon.ico" type="image/x-icon">
  
  ```
  
  Insert Craft's current site handle tag so that you can use the same code on all sites. Then you'll just need to create a paths in your S3 bucket to match.
  
  Regarding multiple sizes, you should include more than just a 16x16 favicon. This is what I have which is all related to icon display:
  
  ```
  <link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
  <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
  <link rel="manifest" href="/site.webmanifest">
  <link rel="mask-icon" href="/safari-pinned-tab.svg" color="#888888">
  <meta name="msapplication-TileColor" content="#ffc40d">
  <meta name="theme-color" content="#ffffff">
  
  ```
  
  The manifest, mask-icon, msapplication-TileColor, and theme-color all refer to how your favicon will appear on platforms including Safari, Windows and Android devices.
  
  You could add an image transform to your asset volume which creates each of the required sizes, or you could direct your client to upload multiple sizes. It may be easier to send them to [this site](https://realfavicongenerator.net/) to generate favicons which they can then upload to their assets volume.
  
  Disclaimer, I have no affiliation to the Favicon Generator site -- I just use it frequently. I generated the code you see above using this tool. If you're looking for a reliable way to generate your favicon size variations and the associated code, this online tool does the trick.
  
  
  ---
  
  