简体   繁体   English

HTML头或htaccess文件中的Apple Touch图标

[英]Apple touch icon in html head or htaccess file

I'm in the process of building a new web application. 我正在构建一个新的Web应用程序。

I've got my favicon and apple icons all ready to go. 我已经准备好了图标图标和苹果图标。 I was wondering if I need to include them in the 'head' of my HTML file - or is routing them from the .htaccess file acceptable? 我想知道是否需要将它们包含在HTML文件的“头”中,或者是否可以从.htaccess文件中路由它们?

HTML code: HTML代码:

<head>
  <link rel="shortcut icon" href="assets/ico/favicon.ico">
  <!-- Standard iPhone --> 
  <link rel="apple-touch-icon" sizes="57x57" href="touch-icon-iphone-114.png" />
  <!-- Retina iPhone --> 
  <link rel="apple-touch-icon" sizes="114x114" href="touch-icon-iphone-114.png" />
  <!-- Standard iPad --> 
  <link rel="apple-touch-icon" sizes="72x72" href="touch-icon-ipad-144.png" />
  <!-- Retina iPad --> 
  <link rel="apple-touch-icon" sizes="144x144" href="touch-icon-ipad-144.png" />
</head>

or just put them in htaccess? 或只是将它们放在htaccess中?

    # Rewrite for Favicons
RewriteRule ^favicon\.ico$ assets/ico/favicon.ico [L]
RewriteRule ^apple-touch-icon\.png$ assets/ico/apple-touch-icon.png [L]
RewriteRule ^apple-touch-icon-57x57\.png$ assets/ico/apple-touch-114-icon.png [L]
RewriteRule ^apple-touch-icon-114x114\.png$ assets/ico/apple-touch-icon-114.png [L]
RewriteRule ^apple-touch-icon-72x72\.png$ assets/ico/apple-touch-icon-144.png [L]
RewriteRule ^apple-touch-icon-144x144\.png$ assets/ico/apple-touch-icon-144.png [L]

Question: Is there any negative to just putting them in my .htaccess file and removing them from my HTML? 问题:将它们放入我的.htaccess文件并将其从HTML中删除是否有负面影响?

You don't have to specify them if you follow Apple's naming convention. 如果遵循Apple的命名约定,则不必指定它们。

From Apple's documentation : 从Apple的文档中

If no icons are specified using a link element, the website root directory is searched for icons with the apple-touch-icon... or apple-touch-icon-precomposed... prefix. 如果未使用link元素指定图标,则在网站根目录中搜索带有apple-touch-icon ...或apple-touch-icon-precomposed ...前缀的图标。 For example, if the appropriate icon size for the device is 57 x 57, the system searches for filenames in the following order: 例如,如果设备的适当图标尺寸为57 x 57,则系统将按以下顺序搜索文件名:

  • apple-touch-icon-57x57-precomposed.png apple-touch-icon-57x57-precomposed.png
  • apple-touch-icon-57x57.png apple-touch-icon-57x57.png
  • apple-touch-icon-precomposed.png apple-touch-icon-precomposed.png
  • apple-touch-icon.png apple-touch-icon.png

Since you are using the same file everywhere you could just use: 由于您到处都使用相同的文件,因此可以使用:

RewriteRule ^apple-touch-icon\.png$ assets/ico/apple-touch-icon.png [L]
RewriteRule ^apple-touch-icon-[0-9].* assets/ico/apple-touch-114-icon.png [L]

Also, why not also send the 114x114 icon to all iPhones? 另外,为什么不同时将114x114图标发送给所有iPhone? What I do a lot is just create one icon of 114x114 and name it apple-touch-icon.png, and place it in the root of the domain. 我要做的只是创建一个114x114的图标,并将其命名为apple-touch-icon.png,并将其放置在域的根目录中。 That way retina get the 114px and older will just resize it to half. 这样,视网膜得到114px,而较老的将其调整为一半。 The only downside is you get a few 404's in the apache error log, but who cares. 唯一的缺点是您会在apache错误日志中看到一些404错误,但谁在乎。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM