<head> 區塊完整解析:Meta、Title、Link、Script、Style、Base 與 SEO 關鍵標籤<head> 必備與選用元素<head>
<meta charset="UTF-8"> <!-- 必須最優先,避免重解析 -->
<title>頁面標題 - 網站名稱</title> <!-- 唯一,50-60 字元最佳 -->
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- RWD 必備 -->
<meta name="description" content="頁面描述 150 字內"> <!-- SEO 摘要 -->
<meta name="keywords" content="關鍵字1, 關鍵字2"> <!-- 現代搜尋引擎權重極低 -->
<link rel="canonical" href="https://example.com/page"> <!-- 規範網址 -->
<link rel="preload" as="font" href="/fonts/heading.woff2" crossorigin>
<link rel="stylesheet" href="/css/main.css" media="print" onload="this.media='all'"> <!-- 非阻塞載入 -->
<script src="/js/main.js" defer></script> <!-- defer 保證 DOM 就緒執行 -->
<script type="application/ld+json">{...}</script> <!-- Schema.org 結構化資料 -->
</head>
| 類別 | name / http-equiv | content 範例 | 用途 |
|---|---|---|---|
| 編碼 | charset | UTF-8 | 字元編碼宣告 (HTML5 簡寫) |
| 視口 | name="viewport" | width=device-width, initial-scale=1.0 | 行動裝置縮放控制 |
| SEO | name="description" | 頁面摘要 | 搜尋結果片段 |
| SEO | name="robots" | index, follow / noindex, nofollow | 爬蟲指令 |
| 社群分享 | property="og:title" | 標題 | Open Graph (FB, Line, LinkedIn) |
| 社群分享 | property="og:image" | https://example.com/og.jpg | 分享縮圖 (1200x630) |
| 社群分享 | name="twitter:card" | summary_large_image | Twitter Card |
| 安全 | http-equiv="Content-Security-Policy" | default-src 'self'; script-src 'self' https://cdn.example.com | CSP 防 XSS (建議用 HTTP 標頭) |
| 快取 | http-equiv="Cache-Control" | no-store, must-revalidate | 頁面快取策略 (建議用 HTTP 標頭) |
| 重新導向 | http-equiv="refresh" | 5;url=https://example.com/new | 延遲跳轉 (不建議,用 301/302) |
| 應用 | name="theme-color" | #0d6efd | 瀏覽器標籤/工具列顏色 |
| 應用 | name="apple-mobile-web-app-capable" | yes | iOS PWA 全螢幕模式 |
<base> 基底網址<base href="https://cdn.example.com/assets/" target="_blank">
頁面所有相對連結將以此為基準,**慎用**,易造成除錯困難、SEO 規範網址混淆。