html文档中元数据的最佳做法? [英] Best practice for meta data in a html document?

查看:108
本文介绍了html文档中元数据的最佳做法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在大规模,大量,面向公众的Web应用程序上工作.应用程序的成功运行对业务非常重要,因此有许多与此相对应的MI工具.

I work on a large scale, high volume, public facing web application. The successful operation of the application is very important to the business, and so there are a number of MI tools that run against it.

这些MI工具中的一个实质上是针对每个页面请求查看发送到浏览器的html(我已经对其进行了很多简化,但是出于这个问题的目的,它是一种对html)

One of these MI tools essentially looks at the html that is sent to the browser for each page request (I've simplified it quite a lot, but for the purpose of this question, its a tool that does some analysis on the html)

为使此MI工具获取所需数据,我们将meta数据放在head元素中.目前,我们将其作为html注释:

For this MI tool to get the data it needs, we put meta data in the head element. Currently we do it as html comments:

<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" class="">
<head>
    <!-- details = 52:AS6[rxSdsMd4RgYXJgeabsRAVBZ:0406139009] -->
    <!-- policy id = 1234567890 -->
    <!-- party id = 0987654321 -->
    <!-- email address = user@email.com -->
    <!-- error = 49 -->
    <!-- subsessionid = bffd5bc0-a03e-42e5-a531-50529dae57e3-->
    ...

该工具只需使用正则表达式查找给定的元数据注释

And the tool simply looks for a given meta data comment with a regex

由于此数据是元数据,因此我想将其更改为html meta标签,因为它在语义上是正确的.像这样:

As this data is meta data, I'd like to change it to html meta tags because it feels semantically correct. Something like this:

<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" class="">
<head>
    <meta name="details" content="52:AS6[rxSdsMd4RgYXJgeabsRAVBZ:0406139009]" />
    <meta name="policyId" content="1234567890" />
    <meta name="partyId" content="0987654321" />
    <meta name="emailAddress" content="user@email.com" />
    <meta name="error" content="49" />
    <meta name="subsessionid" content="bffd5bc0-a03e-42e5-a531-50529dae57e3" />
    ...

这感觉更语义化,我可以让MI工具使用它而没有问题-只是更改正则表达式的一种情况.但是现在它给我w3c验证程序一个问题.由于无法识别我使用的元名称,因此无法验证.我收到错误元素元上的属性名称的错误值详细信息:关键字详细信息未注册".并且建议我在WHATWG Wiki上注册这些名称值.

This feels more semantic, and I can get the MI tool to work with it no problem - just a case of changing the regexes. However it now gives me a problem with the w3c validator. It wont validate because the meta names I'm using are not recognised. I get the error "Bad value details for attribute name on element meta: Keyword details is not registered." and it suggests I register these name values on the WHATWG wiki.

虽然我可以做到,但感觉不对.我的某些元标记是通用的"(例如error和emailAddress),因此我可能可以找到一个已经注册的名称值并使用它.但是,大多数都是特定于行业/组织的.注册一个名为subsessionid或partyId的公共名称值是错误的,因为这些特定于我的组织和应用程序.

Whilst I could do this it doesn't feel right. Some of my meta tags are 'generic' (such as error and emailAddress) so I could probably find an already registered name value and use that. However, most of them are industry/organisation specific. It feels wrong to register a public name value called subsessionid or partyId as these are specific to my organisation and the application.

因此,问题是-在这种情况下,什么是最佳实践?我应该将其保留为html注释吗?我应该像上面那样使用元标记,而不用担心w3c验证失败吗? (尽管这对组织越来越重要)我应该尝试在WHATWG Wiki上注册我的元名称值,但知道它们不是很通用吗?还是有其他解决方案?

So, the question is - what is considered best practice in this case? Should I leave them as html comments? Should I use meta tags as above and not worry that w3c validation fails? (though that is increasingly important to the organisation) Should I attempt to register my meta name values on WHATWG wiki, but knowing they are not very generic? Or is there another solution?

感谢您的想法,欢呼

内森

编辑以显示最终解决方案:

Edited to show the the final solution:

我要使用的完整答案如下.它基于Rich Bradshaws的答案,因此他的答案是可以接受的,但这就是我为了完整起见要使用的内容:

The full answer I'm going with is as follows. Its based on Rich Bradshaws answer, so his is the accepted one, but this is what I'm going with for completeness:

<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" class="">
<head>
    <meta name="application-name" content="Our app name" 
        data-details="52:AS6[rxSdsMd4RgYXJgeabsRAVBZ:0406139009]" 
        data-policyId="1234567890"
        data-partyId="0987654321"
        data-emailAddress="user@email.com"
        data-error="49"
        data-subsessionid="bffd5bc0-a03e-42e5-a531-50529dae57e3"
    />
    ...

这可以验证,因此所有方框均打勾:)

This validates, so all boxes ticked :)

推荐答案

W3C验证是没有意义的. HTML!= XML,因此没有任何架构可对其进行验证.没有浏览器会阻塞,因为您添加了一个具有未注册名称的meta元素.如果您真的很担心,可以在meta元素上使用data属性,例如:

W3C validation is meaningless. HTML != XML, so there isn't any schema to validate it. No browser will choke because you added a meta element with an unregistered name. If you really are worried, you could use the data attribute on a meta element like:

<meta data-details="52:AS6[rxSdsMd4RgYXJgeabsRAVBZ:0406139009]" data-policyId="0123456789" />

至少您不知道将来的规范会给您的数据带来任何意义.

at least then you know no future spec will give meaning to your data.

有关更多信息,请阅读: http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#custom-data-attribute

For more info read: http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#custom-data-attribute

这篇关于html文档中元数据的最佳做法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆