? ? ? ?meta元素是一個元數(shù)據(jù)內(nèi)容,常用于定義頁面的說明,關(guān)鍵字、最后修改日期等元數(shù)據(jù),這些元數(shù)據(jù)將服務(wù)員瀏覽器、搜索引擎以及其它網(wǎng)絡(luò)服務(wù)。
meta標(biāo)簽共有兩個屬性,分別是http-equiv屬性和name屬性。
name屬性:
? ? ? name屬性主要用于描述網(wǎng)頁,如關(guān)鍵字、敘述,與之相對于的屬性值為content;主要常用的有以下幾種參數(shù):
1:keywords(關(guān)鍵字):告訴搜索引擎,你的網(wǎng)頁關(guān)鍵詞:
? ? ? 格式:<meta name="keywords" content="商品 前端 書籍">
2:description(網(wǎng)站內(nèi)容的描述):告訴引擎你的網(wǎng)站主要內(nèi)容:
? ? ? 格式:<meta name="description" content="這是我寫的第一篇meta">
3:viewport(移動端窗口):長用于手機(jī)端或者無線端:
? ? ? 格式:<meta name="viewport" content="width=device-width,initial-scale=1">
4:robots(定義搜索 引擎爬蟲的索引方式):content的參數(shù)有all(默認(rèn) ),none,index,follow,nofollow.
? ? ? 格式:<meta name="robots" content="none">
5:author(作者):標(biāo)注網(wǎng)頁作者:
? ? ?格式:<meta name="author" content="hahahah">
6:copyright(版權(quán)信息)
7:revisit-after(搜索引擎爬蟲重訪時間):如果頁面更新不快,可以設(shè)定一個搜索引擎爬蟲重訪時間以減輕服務(wù)器壓力:
? ? ? 格式:<meta name="revisit-after" content="10 day">
8:renderer(雙核瀏覽器渲染方式)指定雙核瀏覽器默認(rèn)渲染方式:
? ? ? webkit(默認(rèn)以webkit內(nèi)核);ie-comp(默認(rèn)IE兼容模式);ie-stand(默認(rèn)IE標(biāo)準(zhǔn)模式)
http-equiv屬性
1:content-Type(設(shè)定網(wǎng)頁字符集):建議用html5方式:
? ? ? <meta charset="utf-8">
2:X-UA-Compatible(瀏覽器 采取何種版本渲染當(dāng)前頁面):一般設(shè)置為最新模式:
? ? ? ? ?<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>(IE和chrome使用最新版本渲染)
3:cache-control(指定請求和響應(yīng)遵循的緩存機(jī)制)
? ? ? ? no-cache:先發(fā)生,和 服務(wù)器確認(rèn)是否更改,如果沒有更改,則使用緩存。
? ? ? ? no-store:不允許緩存
? ? ? ? public:緩存所有的相應(yīng),但并非一定;
? ? ? ? ?private:只為單個用戶緩存,不允許任何中繼進(jìn)行緩存。
? ? ? ? ?maxage:標(biāo)識當(dāng)前請求開始,改相應(yīng)應(yīng)在多久內(nèi)能緩存和重用,而不去服務(wù)器重新請求。例如:max-age=60表示響應(yīng)可以再緩存和重用60s.
? ? ? ? ?no-siteapp:不允許自動轉(zhuǎn)碼;
4:Pragma(cache模式):禁止瀏覽器從本地計算機(jī)緩存中訪問頁面,訪問者將無法脫機(jī)瀏覽。
? ? ? ?格式<meta http-equiv="pragma" content="no-cache">
5:Refresh(刷新):自動刷新并指向新頁面:
? ? ? ?格式<meta http-equiv="Refresh" content="2,URL=新的頁面鏈接”>停留2s,自動刷新到新的頁面。
6:Set-Cookie:設(shè)置cookie,如果網(wǎng)頁過期,那么舊cookie將被刪除。
? ? ? ?<meta http-equiv="Set-Cookie" content="cookievalue=xxx;expires=Monday,12 Jan 2020 20:20:20 GMT;path=/">
7:Window-target(顯示窗口設(shè)定)防止別人在框架里調(diào)用自己的頁面:
? ? ? ?<meta http-equiv="Window-target" content="_top">