Hacker News 中文摘要

RSS订阅

过时的 HTML 代码片段与遗留产物 -- Antiquated HTML Snippets and Artefacts

随着设备、浏览器、操作系统、工具和企业利益不断变化,网络持续变动,所写 HTML 也随之改变。自 HTML 语言诞生,规范每行改动伴生更多片段经历环境变化,适应不同浏览器、扩展与系统。因第三方集成、浏览器竞争、供应商扩展和平台黑客潜入网站的代码片段,曾因故加入,今因无关遗忘,只存旧站标记和浏览器战争亲历者记忆中。

正文

网络设备、浏览器、系统、规范、偏好、工具和企业利益瞬息万变,网页持续浮动,我们写的 HTML 亦然。相比规范自身的改动,更多片段经历了“环境”变化——为适应不同浏览器、扩展、集成和系统而生。以下内容不谈曾入规范但已废弃的 HTML,只看那些因第三方集成、浏览器竞争、厂商扩展或平台 hack 而钻进网站的代码片段。它们曾有理由,如今因无关遭遗忘,只活在旧站点的标记和浏览器战争亲历者脑中。

X-UA-Compatible

<meta http-equiv="X-UA-Compatible" content="IE=edge">

浏览器快速迭代、版本特定行为常见的年代,需用此标签声明兼容特定浏览器版本。此处 IE=edge 指目标为 IE 支持的最高文档模式。文档还记有其他值:如 5 到 11 对应 IE 版本,或 EmulateIE7 到 EmulateIE11 进入对应模式(须合法 DOCTYPE,否则怪异模式)。

<meta http-equiv="X-UA-Compatible" content="chrome=1">

Chrome 统治前,谷歌发布 IE 插件 Google Chrome Frame(支持 IE6-9),带此标签的站点会用 Chrome 改版 WebKit 引擎而非 IE 的 Trident 渲染。

<meta http-equiv="X-UA-Compatible" content="requiresActiveX=true">

requiresActiveX 用于 IE10 在 Metro 模式不支持插件时,提示切到桌面模式。

ICBM Coordinate

<meta name="ICBM" content="-31.9548, 115.8602">

ICBM(洲际弹道导弹缩写)是 Usenet 时代指地理坐标的黑客俚语。该标签标网站主体位置,被 GeoURL 服务用来在全球标点并找邻近站点。

<!--[if gte IE 6]><p>Only shown in Internet Explorer 6 and higher.</p><![endif]-->

浏览器频更、战争激烈时,常需针对特定浏览器或版本。微软在 IE 用特殊格式注释。可用操作符细化条件,包括:IE 加版本号;lt 小于、lte 小于等于、gt 大于、gte 大于等于;! 非、& 与、| 或;括号子表达式;以及恒真 true、恒假 false。

<!-- &{navigator.appName == 'Netscape'}; <p>Only shown in Netscape.</p>-->

Netscape 用紧跟注释开标签的 JS 实体做条件注释,真则包含,假则仅注释;非 Netscape 浏览器总当普通注释。

<meta name="MSSmartTagsPreventParsing" content="TRUE">

IE6 的 Smart Tags 会自动向页面注入超链接(如识别大公司名给股票链接),站长哗然,遂出此标签退出。微软后来从 IE 彻底移除该功能。

PICS

<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.gcf.org/v2.5" labels on "1994.11.05T08:15-0500" until "1995.12.31T23:59-0000" for "http://w3.org/PICS/Overview.html" ratings (suds 0.5 density 0 color/hue 1))'>

90 年代中期 W3C 推互联网内容标注规范 Platform for Internet Content Selection (PICS),融入多款过滤产品及 IE3+。页面可含此标签标注自己。但许多站长谎报或错标,更多从不添加。后续的 Protocol for Web Description Resources (POWDER) 也未成功,PICS 约 2003 年全弃。

Interpage Transitions

<meta http-equiv="Page-Enter" content="revealTrans(Duration=2.0,Transition=12)"> <meta http-equiv="Page-Exit" content="revealTrans(Duration=2.0,Transition=12)">

如同 PPT 或 Keynote 设切换,IE4 至 8 支持上述标签做过渡特效。此特性直到 View Transition API 被采纳才正式进 Web 平台。开发者 Bramus 已将 IE 过渡移植到新 API。

Frame Buster

<meta http-equiv="Window-target" content="_top">

自 90 年代中期 Netscape Navigator 起,后延至 IE 等,此非标准标签让在框架中加载的页面跳出父页、开独立窗口。_top 指定页面载于顶层窗口。站长常用它防页面被别站框嵌入。现代用安全头防嵌入。

Baidu Page Transcoding

<meta name="applicable-device" content="pc,mobile"> <meta http-equiv="Cache-Control" content="no-siteapp,no-transform">

Baidu Browser 手机版曾有极不受欢迎的页面“转码”功能:站点经 transcoder.baidu.com 被改版(重构布局、剥样式、压图片、去品牌和原广告,注入百度联盟广告),严重破坏站点。2012 至 2018 年间,站长按上述标签退出转码。

Skype Toolbar

<meta name="skype_toolbar" content="skype_toolbar_parser_compatible">

IE、Chrome、Firefox 曾有个随 Skype 安装的 Skype Toolbar(后名 Skype Click to Call)插件,侦测页面电话号码显可点图标。插图标常致页面崩,开发者加此标签禁掉。该扩展在 Firefox 极不稳,2011 年被 Mozilla 明确拦截。

Image Toolbar

<meta http-equiv="imagetoolbar" content="no">

IE6 加了悬于图片上显保存分享等钮的 Image Toolbar,开发者厌此侵扰,用上标签禁功能。

ClearType

<meta http-equiv="cleartype" content="on">

ClearType 是微软改善排版清晰度的系统。此标签让低分屏(如 Pocket IE / IE Mobile)排版更佳。

AJAX Crawling

<meta name="fragment" content="!">

谷歌爬页原不跑 JS,AJAX 内容不索引。此标签告谷歌爬虫请求带 _escaped_fragment_ 参数的页,期望返 HTML 版。谷歌 09 荐此道,15 弃。

Directory

<meta name="robots" content="noodp, noydir">

网目录(如 Yahoo Directory、DMoz)曾流行,它们有时自写站点标题描述被某些引擎用。此标签信号引擎用页上元数据而非目录的。两目录皆亡,片段无关。

Web App Name

<meta name="application-name" content="App Title">

PWA 确立前,各浏览器 web app 实现用 application-name,缺则退用 <title>。

Internet Explorer Pinned Sites

<meta name="msapplication-tooltip" content="Visit our site!"> <meta name="msapplication-starturl" content="./"> <meta name="msapplication-window" content="width=1024;height=768"> <meta name="msapplication-navbutton-color" content="#FF3300"> <meta name="msapplication-task" content="name=Blog;action-uri=/blog;icon-uri=/favicon.ico">

Win7 上 IE9+ 可将站钉任务栏,钉后暴露系统级站点功能似现代 PWA。msapplication-tooltip 悬图标显字,msapplication-starturl 设根 URL,msapplication-window 设初窗口尺寸(最小宽 800 高 600),msapplication-navbutton-color 设前后导航钮色,msapplication-task 定义右键钉站快捷操作(如博客链)。

Microsoft Web Apps

<meta name="msapplication-TileColor" content="#FF3300"> <meta name="msapplication-TileImage" content="/mstile-144x144.png"> <meta name="msapplication-square70x70logo" content="/images/small-tile.png"> <meta name="msapplication-square150x150logo" content="/images/medium-tile.png"> <meta name="msapplication-wide310x150logo" content="/images/wide-tile.png"> <meta name="msapplication-square310x310logo" content="/images/large-tile.png"> <meta name="msapplication-config" content="/browserconfig.xml">

类似钉站,这些值管呈现。msapplication-TileColor、msapplication-TileImage 及诸 square*/wide* 标签设各 Windows 版(桌面、Metro、Win Mobile)磁贴主题。

<meta name="msapplication-badge" value="frequency=360;polling-uri=https://contoso.com/BadgeUpdate.aspx">

msapplication-badge 定义被轮询通知的网址,显于站点 Live Tile。

Chrome Pinned Web Apps

<meta name="application-url" content="https://vale.rocks">

Chrome 曾用 application-url 作钉 web app 起始 URL。

CRX-less Web Apps

<link rel="chrome-application-definition" href="application_definition.json">

CRX-less Web Apps 是 Chrome 用在线 manifest 描托管 app 的应用。上标签链 JSON manifest(含 name、description、launch_url 等)。此类 app 仅传 JSON 和图标上 Chrome 店,不需扩展用的 .crx 格式。后改名 Chrome Apps,正逐步淘汰。

iOS Web Apps

<link rel="apple-touch-icon" href="/custom_icon.png"> <link rel="apple-touch-startup-image" href="/splash.png"> <meta name="apple-mobile-web-app-title" content="App Name"> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">

为让站长自定 iOS 加主屏体验,苹果引上述标签。图标、启动图、标题不言自明;apple-mobile-web-app-capable 禁浏览器 chrome,apple-mobile-web-app-status-bar-style 设系统状态栏三选一:

  • default:白底黑字黑图。
  • black:黑底黑字黑图。
  • black-translucent:背景取网页色,白字白图。

现被现代 PWA 定义替。

<meta name="apple-touch-fullscreen" content="yes">

apple-touch-fullscreen 曾用于 iOS2 早期 demo,但苹果文档只反射 apple-mobile-web-app-capable。因早 demo 流行,它先于功能发布被推广,苹果遂使之成别名。

UC Browser and QQ Browser

<meta name="screen-orientation" content="portrait"> <meta name="x5-orientation" content="portrait"> <meta name="full-screen" content="yes"> <meta name="x5-fullscreen" content="true">

2010 年代早中期,UC Browser 和 QQ Browser 因省流量、优廉机在亚洲流行。UC 用 screen-orientation 强制方向、full-screen 隐 chrome;QQ 用 x5-orientation 和 x5-fullscreen 做同样事(X5 指腾讯 X5 引擎)。标准全屏和方向 API 及强浏览器普及后,不再需这些。

PDA Optimised

<meta name="HandheldFriendly" content="true"> <meta name="MobileOptimized" content="320">

<meta name="viewport" content="width=device-width"> 普前,这些标签广用于移动。HandheldFriendly 为 AvantGo 创后扩至 Blackberry Browser;MobileOptimized 是微软为老 Windows Mobile 造。

Internet Explorer Tap Highlight

<meta name="msapplication-tap-highlight" content="no">

此片段禁 IE11 链点高亮,似 -webkit-tap-highlight-color,但仅布尔不改色。

Revisit-After

<meta name="revisit-after" content="7 days">

Vancouver Webpages 站的 niche 区域搜索系统 searchBC(BC 指不列颠哥伦比亚)用此标签知重抓频度。唯此已知用途,无证据主流引擎(含谷歌)用过。尽管如此,它如 SEO 神话传遍网。

Page Prerendering

<link rel="prerender" href="https://example.com">

仅 Chrome13-62 全支持且未入规范,会抓取预处理页备导航。功能被 Speculation Rules API 替。

Accelerated Mobile Pages Version

<link rel="amphtml" href="https://example.com/amp.html">

Accelerated Mobile Pages (AMP) 是加速重排页,此标签链其版。现 AMP 不广用、谷歌不推,标签不需。

Internet Explorer Reading View

<meta name="IE_RM_OFF" content="true">

IE9 起有 Reading View 简版阅读钮,页加此标签退出生效钮。

Really Simple Discovery

<link rel="EditURI" href="https://example.com/xmlrpc.php?rsd" type="application/rsd+xml" title="RSD">

Really Simple Discovery (RSD) 暴博管服务给客户端。头内部链 XML 给 Windows Live Writer 等连。多平台(WP、Blogger 等)实现,现代出版系统多废。

Pingbacks

<link rel="pingback" href="https://example.com/xmlrpc.php">

Pingbacks 是站链他站时警报,收方核验真链后记“某站链了”,似 WebMentions。但速成 spam 和 SEO 作弊途径落伍,致 DDoS 漏洞也被利用。

<link rel="image_src" href="https://example.com/post/image.png"> <link rel="audio_src" href="https://example.com/post/audio.mp4"> <link rel="video_src" href="https://example.com/post/video.mp4">

Facebook 创 Open Graph 前用 Share Partners 定嵌入元数据,多站采为事实标准(如 Digg)。image_src 嵌图、audio_src 嵌音、video_src 嵌视频,诸标签支持度不一。

Twitter Embeds

<meta name="twitter:card" content="summary"> <meta name="twitter:site" content="@account"> <meta name="twitter:creator" content="@writer_account"> <meta name="twitter:url" content="https://example.com/posts/hello-world"> <meta name="twitter:title" content="Title"> <meta name="twitter:description" content="Page description"> <meta name="twitter:image" content="https://example.com/hello-world-embed-image.png"> <meta name="twitter:image:alt" content="Alternative text for the image.">

这些标签(及些少用者)曾供 Twitter 生链嵌入,但文档和校验器已不可达。X 退用广受尊的 Open Graph 标签,使推特专属声明无用,应删以就 Open Graph。

<meta name="twitter:dnt" content="on">

Twitter 另有 Do Not Track 标签退 Widgets 追踪,文档不可达,似不再受尊。

这不详尽,只列较流行显要非标准片段。更多 obscure 碎片漂网空,好奇者可见 WhatWG Wiki。

评论

讨论气氛整体是“怀旧式考古”:被 IE 条件注释、doctype、字符集问题折磨过的人一边翻旧账一边庆幸这些问题终于消停,也有人觉得 GeoURL、PICS 这类没能成气候的技术死得可惜。真正的分歧在于“旧声明是否该爽快删干净”,Twitter 卡片标签的去留在同一条评论里就出现了反复。

IE 留下的疤痕:条件注释、PNG hack、doctype 与编码错乱

  • 有评论者直到 2020 年前后还在维护 IE 专属回退,msapplication-* 字段可能拖到 2021 年之后才清理;IE 修 PNG 透明度的 AlphaImageLoader 滤镜写法则“永远刻在脑子里”。(较多人)
  • 早年一个 doctype 就要写一长串 W3C URL,普通开发者只能从教程整段复制;字符集和 BOM 的坑则让挪威语字母 æøå 随机变成乱码。如今“UTF-8 一路用到底就好”,整体上已是难得的省心。(较多人)

旧兼容层就像墙脚的泥,堆着反而是历史感的证据

  • 有人觉得大量老代码堆在墙脚是正常甚至健康的信号;真正值得担心的是这个清单某天不再增长。ta 同时惋惜 <?xml-stylesheet?> 处理指令和 JavaScript XSLTProcessor API 的消失。(少数人)
  • 做超兼容框架、目标覆盖 Netscape 3.x 到现代浏览器的开发者专门感谢这份清单;也有人还记得早期网页上的“设为主页”“加入收藏”小图标,虽然自己从没用过,但看到会觉得亲切。(少数人)

Twitter 卡片:支持删除的人也没能把话说死

  • 一位评论者主张 Twitter 专属 meta 标签该让位给 Open Graph,理由是 X 的官方文档和卡片验证器已经无法访问,X 会回退到 Open Graph;ta 还因平台本身的政治立场而不愿继续为它服务。(少数人)
  • 但 ta 随即承认 twitter:card 没有 Open Graph 等价字段,可能仍然有效。可见“可以删”和“删得干净”是两回事。(同一评论者)

有价值的补充

  • viewport meta 不必同时写 width=device-width, initial-scale=1;只要给出 initial-scale=1,iOS Safari 会自行推断竖屏时宽度等于 device-width,评论者称已实测验证。
  • 清单漏了 Safari 固定标签页(Pinned Tabs)的 meta:需要准备一张简单的黑白 SVG,激活时 Safari 用主题色绘制,不激活时显示为黑色。
  • 服务端图像热区被点名是“另一个好玩的旧东西”,同样容易被遗忘。
  • 很少见地有人为 PICS 这类早期网络内容筛选框架翻案,认为它设计得不错,没有流行起来很可惜。