head 區指的是 <head> 與 </head> 之間的所有內容。這裡放的不是給人看的畫面,而是給瀏覽器與搜尋引擎讀的資訊,寫得完整與否,直接影響編碼是否正確、搜尋結果摘要是否漂亮。
1. 版權或製作資訊註解
<!-- The site is designed by webjx.com 06/2006 -->
2. 字元編碼宣告(決定中文會不會變亂碼,務必放在最前面)
<meta http-equiv="Content-Type" content="text/html; charset=big5"> <!-- 繁體中文 --> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <!-- 簡體中文 --> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <!-- 英文 -->
3. 作者資訊
<meta name="author" content="Evance">
4. 網站簡介,這段文字常會被搜尋引擎拿去當摘要:
<meta name="description" content="xxxxxxxx">
5. 搜尋關鍵字
<meta name="keywords" content="xxxx,xxxx,xxx,xxxxx">
6. 外部樣式表
<link href="style/style.css" rel="stylesheet" type="text/css">
7. 網頁標題,會顯示在瀏覽器分頁上,也是搜尋結果的標題:
<title>xxxxxxxx</title>
到期時間:過期後必須回伺服器重新抓取。
<meta http-equiv="expires" content="Wed, 26 Feb 2006 08:21:57 GMT">
禁用本機快取:適合內容經常變動的頁面。
<meta http-equiv="Pragma" content="no-cache">
防止被別人的框架內嵌
<meta http-equiv="Window-target" content="_top">
自動轉址:數字 5 代表停留 5 秒後跳轉。
<meta http-equiv="Refresh" content="5;URL=https://www.example.com">
搜尋引擎機器人指引:content 可填 all、none、index、noindex、follow、nofollow,預設為 all。
<meta name="robots" content="none">
我的最愛小圖示(favicon)
<link rel="shortcut icon" href="favicon.ico">
JavaScript 外部化:盡量把程式碼抽到獨立檔案,head 會乾淨很多。
<script language="javascript" src="script/xxxxx.js"></script>
<body> 並不屬於 head 區,但為了避免不同瀏覽器出現預設底色差異,建議明確指定背景顏色:
<body bgcolor="#FFFFFF">
實務上的順序建議是:編碼宣告放在最前面,接著是 title 與 meta 說明,最後才載入樣式表與程式檔。把這份清單存成範本,每開一個新專案直接複製,能省下不少重複輸入的時間。