Best practice for meta data in a html document?

后端 未结 4 876
猫巷女王i
猫巷女王i 2020-12-24 00:10

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

相关标签:
4条回答
  • 2020-12-24 00:41

    While your example may work, note that the keyword application-name is for Web applications only.

    For usual webpages not being web applications, or if no application-name shall be given, see some alternatives:

    Using data-* attributes in the head

    No need for a meta element.

    <!DOCTYPE html>
    <html>
    <head
        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">
    </head>
    

    Using Microdata

    You could create a vocabulary, but that’s not required for local use.

    <!DOCTYPE html>
    <html>
    <head itemscope>
      <meta itemprop="details" content="52:AS6[rxSdsMd4RgYXJgeabsRAVBZ:0406139009]" />
      <meta itemprop="policyId" content="1234567890" />
      <meta itemprop="partyId" content="0987654321" />
      <link itemprop="emailAddress" href="mailto:user@email.com" /> <!-- or use a meta element if you don’t want to provide a full URI with "mailto:" scheme -->
      <meta itemprop="error" content="49" />
      <meta itemprop="subsessionid" content="bffd5bc0-a03e-42e5-a531-50529dae57e3" />
    </head>
    

    Using data in a script

    The script element can be used for data blocks. You can choose any format that suits your needs. Example with plain text:

    <!DOCTYPE html>
    <html>
    <head>
      <script type="text/plain">
        details = 52:AS6[rxSdsMd4RgYXJgeabsRAVBZ:0406139009]
        policyId = 1234567890
        partyId = 0987654321
        emailAddress = user@email.com
        error = 49
        subsessionid = bffd5bc0-a03e-42e5-a531-50529dae57e3
      </script>
    </head>
    
    0 讨论(0)
  • 2020-12-24 00:45

    Either option would technically work, although the solution could come down to how your organisation feels about page validation.

    As you say, adding information into custom metadata tags will invalidate your markup.

    For my organisation, page validation is part of technical accessibility and is considered very important. Doing anything that would prevent pages from validating would not be allowed.

    I wouldn't attempt to register new metadata names and values as these are specific to your organisation and not for public use.

    I would probably leave this information as HTML comments if this is already working for your organisation.

    0 讨论(0)
  • 2020-12-24 00:47

    What if you try using the data- format to add a custom attribute to them, something like data-type or data-name and omitting the real name attribute or maybe setting it all to "abstract" or something (I donno if the validator will give problems for repeated meta names):

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

    So you could reference to that data-name to work with your meta stuff...

    http://html5doctor.com/html5-custom-data-attributes/

    0 讨论(0)
  • 2020-12-24 00:57

    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.

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

    0 讨论(0)
提交回复
热议问题