https://aboooks.tistory.com/352
https://blog.munilive.com/posts/meta-tag-property-and-use-method.html
<meta>
<meta>
는 웹 페이지의 metadata를 정의하여, HTTP 헤더를 설정할 수 있고 검색엔진에 노출되는 횟수를 증가시킬 수 있다.<meta>
의 Attributes로는 name
, http-equiv
, charset
, itemprop
이 있다.<html>
<head>
<meta charset="utf-8">
<meta http-equiv="refresh" content="10">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="X-UA-Compatible" content="ie=edge">
</head>
<body>
</body>
</html>
<meta http-equiv="http응답헤더이름" content="응답헤더에 할당할 값"
의 형태로 사용
서버는 클라이언트로부터 요청에 의해 HTTP 프로토콜로 응답을 전달하게 된다. HTTP response 헤더에는 웹 서버의 정보, html 문서의 저자, 만기일, 키워드 목록과 같은 문서의 속성이나, refresh등의 명령어가 포함된다. 우리는 <meta>
의 http-equiv를 이용해서 HTTP 헤더에 담길 명령어나 정보를 설정할 수 있다. http 응답 헤더의 항목이라면 모두 사용 가능한 것으로 알고 있다.
<meta http-equiv="refresh" content="10">
<meta http-equiv="refresh" content="5;url=http://www.another.com">
<meta http-equiv="Expire" content="-1">
<meta http-equiv='Cache-Control' content='no-cache'>
<meta http-equiv="Last-Modified" content="14 Feb 2022 00:00:00">
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
charset
속성을 사용한다.
name
속성과http-equiv
는 동일한 역할을 한다. 예를 들어,<meta name="X-UA-Compatible" content="ie=edge">
와<meta http-equiv="x-ua-compatible" content="ie=edge">
은 동일하다.
기존에 문자셋 설정은 <meta http-equiv="content-type" content="text/html; charset=UTF-8">
로 했지만 HTML5에 charset
속성이 추가되어, <meta charset="utf-8">
로 간단하게 사용이 가능해졌다.
<meta charset="utf-8">
http-equiv 속성을 대신하여 사용할 수 있다. 보통 name 속성은 검색엔진 최적화(SEO)를 위해 사용하는 편이다. 검색엔진 최적화를 위한 name 속성은 아래에서 자세히 설명하겠다. http-equiv에 없고, name 속성에서 사용 가능한 것은 viewport
가 있다.
Viewport
<meta name="viewport">
설정이 필수적이다.width
는 viewport의 가로 길이, initial-scale
은 배율을 의미한다. <meta>
에서 width는 기본 단위가 px
이며, 단위를 써주지 않는다.<meta name="viewport" content="width=300">
<meta name="viewport" content="width=device-width">
<meta name="viewport" content="height=device-width">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="viewport" content="user-scalable=no, width=device-width">
웹페이지를 만들어도 다른 사람이 웹페이지에 접근할 수 있어야 의미가 있다. 검색엔진들은 봇을 이용해 웹 페이지들을 수집하고 분류한다. 우리의 웹 페이지가 자주 노출되려면 검색엔진 봇이 웹 페이지를 잘 분류 할 수 있도록 도와야 한다. 이때, <meta>
태그를 이용하여 웹페이지를 설명하는 정보를 작성하여 검색 엔진 봇을 돕는다.
웹페이지 내용물에 대한 요약, 웹 페이지 검색될 때의 키워드는 무엇인가를 정의할 때 <meta>
태그를 사용한다.
<html>
<head>
<meta name="robots" content="all">
<meta name="robots" content="index,follow">
<meta name="description" content="컨텐츠 요약">
<meta name="keywords" content="단어1,단어2,단어3">
<meta name="author" content="marullo">
</head>
<body>
</body>
</html>
<meta name="robots">
검색 엔진 봇에 대한 접근 권한을 제어하기 위해 사용한다.
<meta name="robots" content="all">
<meta name="robots" content="index,follow" />
<meta name="robots" content="noindex,follow" />
<meta name="robots" content="index,nofollow" />
<meta name="robots" content="noindex,nofollow" />
<meta name="description" >
<meta name="description" content="짧은 소개">
<meta name="keywords">
<meta name="keywords" content="단어1,단어2,단어3">
위에서 작성한 metadata는 검색엔진이 분류하고 저장 하는 것을 도운 것이라면, OG는 실제로 웹 페이지가 노출될 때, 어떤 대표 타이틀, 어떤 대표 이미지를 사용할 것인가를 정의하는 것이다. 우리 페이지가 노출될 때 웹 페이지 링크만 보이는 것이 아니라 이미지나 요약 또한 보이게 하려면 OG를 사용해야 한다. 각 검색 엔진마다 OG에 대한 프로토콜이 다를 수 있으므로 확인하자.
<html>
<head>
<!--<meta name="robots" content="all">
<meta name="robots" content="index,follow">
<meta name="description" content="컨텐츠 요약">
<meta name="keywords" content="단어1,단어2,단어3">
<meta name="author" content="marullo">-->
<meta property="og:url" content="">
<meta property="og:type" content="">
<meta property="og:title" content="">
<meta property="og:image" content="">
<meta property="og:description" content="">
</head>
<body>
</body>
</html>
Open Graph에는 기본적인 5가지 속성이 있다.
<meta property="og:url">
<meta property="og:url" content="https://abc.com/something">
<meta property="og:type">
<meta property="og:type" content="website">
<meta property="og:title">
<meta property="og:title" content="내 타이틀">
<meta property="og:image">
<meta property="og:image" content="http://이미지경로.com/images/something.jpg">
<meta property="og:description">
<meta property="og:description" content="요약">