Programing

HTML 문서의 메타 데이터에 대한 모범 사례?

lottogame 2020. 11. 9. 07:40
반응형

HTML 문서의 메타 데이터에 대한 모범 사례?


저는 대규모의 대량 공개 웹 애플리케이션을 작업하고 있습니다. 애플리케이션의 성공적인 운영은 비즈니스에 매우 중요하므로 이에 대해 실행되는 많은 MI 도구가 있습니다.

이러한 MI 도구 중 하나는 기본적으로 각 페이지 요청에 대해 브라우저로 전송되는 html을 확인합니다 (매우 단순화했지만이 질문의 목적을 위해 html에서 일부 분석을 수행하는 도구).

이 MI 도구가 필요한 데이터를 얻기 위해 헤드 요소에 메타 데이터를 넣습니다. 현재 우리는 HTML 주석으로 수행합니다.

<!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-->
    ...

이 도구는 단순히 정규식을 사용하여 주어진 메타 데이터 주석을 찾습니다.

이 데이터는 메타 데이터이므로 의미 상 정확하다고 느껴지므로 html 메타 태그로 변경하고 싶습니다. 이 같은:

<!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 위키에 이러한 이름 값을 등록 할 것을 제안합니다.

내가 이것을 할 수 있지만 그것은 옳지 않다고 생각합니다. 내 메타 태그 중 일부는 '일반'(예 : 오류 및 emailAddress)이므로 이미 등록 된 이름 값을 찾아서 사용할 수 있습니다. 그러나 대부분은 산업 / 조직에 따라 다릅니다. subsessionid 또는 partyId라는 공개 이름 값을 등록하는 것은 내 조직과 응용 프로그램에 고유하므로 잘못된 것 같습니다.

따라서 질문은-이 경우 모범 사례로 간주되는 것은 무엇입니까? html 주석으로 남겨야합니까? 위와 같이 메타 태그를 사용해야하고 w3c 유효성 검사가 실패 할 염려가 없나요? (조직에 점점 더 중요해 지지만) WHATWG 위키에 메타 이름 값을 등록해야하지만 그다지 일반적이지 않다는 것을 알고 있어야합니까? 아니면 다른 해결책이 있습니까?

당신의 생각을 감사하고, 환호합니다

나단


최종 솔루션을 표시하도록 편집되었습니다.

내가 갈 완전한 대답은 다음과 같습니다. Rich Bradshaws의 답변을 기반으로하므로 그의 답변이 허용되지만 이것이 완전성을 위해 제가 사용하는 것입니다.

<!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"
    />
    ...

이것은 유효성을 검사하므로 모든 상자가 선택되었습니다. :)


W3C 유효성 검사는 의미가 없습니다. HTML! = XML이므로 유효성을 검사 할 스키마가 없습니다. 등록되지 않은 이름의 메타 요소를 추가했기 때문에 브라우저가 질식하지 않습니다. 정말 걱정된다면 다음과 같은 메타 요소에 데이터 속성을 사용할 수 있습니다.

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

적어도 미래 사양이 데이터에 의미를 부여하지 않는다는 것을 알고 있습니다.

자세한 내용은 http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#custom-data-attribute를 참조하십시오.


예제가 작동 할 수 있지만 키워드 application-name웹 응용 프로그램 전용입니다.

웹 응용 프로그램이 아닌 일반적인 웹 페이지의 경우 또는 제공되지 않는 경우 application-name몇 가지 대안을 참조하십시오.

data-*속성 사용head

meta요소 가 필요하지 않습니다 .

<!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>

마이크로 데이터 사용

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>

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/


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.

참고URL : https://stackoverflow.com/questions/10533764/best-practice-for-meta-data-in-a-html-document

반응형