總覽
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Google AMP 快取會提供有效發布到網路的有效 AMP 內容快取副本。
直接從 Google AMP 快取提供內容,提供快速的使用者體驗。
如要善用 Google AMP 快取功能,您必須使用 AMP 快取網址格式,直接從快取存取 AMP 網址。每次使用者從快取存取 AMP 內容時,內容都會自動更新,並在快取內容後提供給下一位使用者。
AMP 快取網址格式包含下列元件:
元件 |
說明 |
子網域名稱 |
字元限制和技術規格允許時,Google AMP 快取建立的子網域會清晰易懂,並與發布商自有網域非常接近。Google AMP 快取會在可行情況下建立下列子網域:
- 將 AMP 文件網域從 IDN (Punycode) 轉換為 UTF-8。
- 將每個「-」(破折號) 分別替換為「--」(2 個破折號)。
- 將每個「.」(點) 換成「-」(破折號)。
- 正在轉換回 IDN (Punycode)。
舉例來說,pub.com 會對應到 pub-com.cdn.ampproject.org 。如果技術限制導致使用者無法判讀子網域,系統會改用單向雜湊。 |
內容類型 |
內容類型是下列其中一種:AMP HTML 文件的「c」代表圖片、「i」代表圖片,「r」代表字型等資源。Google AMP 快取會針對與這類內容類型相符的資源傳回 404 錯誤 (請參閱核心錯誤)。 |
選用的「s」 |
如果有的話,你必須要求 Google 使用傳輸層安全標準 (TLS) 從來源擷取內容。如果沒有「'」,代表內容使用純 HTTP 從來源中擷取。 |
URI |
要擷取的內容 URI。URI 不得採用配置,也就是無「http://」或「https://」。 |
尋找子網域名稱
一般來說,Google AMP 快取網址的子網域會以使用者可理解的方式轉換原始網址。但是,如果是某些情況下可能不合乎需求,建議您使用 Google AMP Cache URL API,擷取可用於實際工作環境的應用程式的 Google AMP 快取網址。
如要針對非實際工作環境情況,判斷 Google AMP 快取產生的子網域名稱,請嘗試在 amp.dev 上使用使用 Google AMP 快取互動工具。
使用傳輸層安全標準 (TLS) 要求文件的範例
要求從 https://example.com/amp_document.html
擷取的 AMP HTML 文件 (使用 /c
前置字元指定):
https://example-com.cdn.ampproject.org/c/s/example.com/amp_document.html
由於 /s
加上 /c
前置字串,因此系統會使用傳輸層安全標準 (TLS) 從 example.com 擷取文件。
使用純 HTTP 要求圖片的範例
要求從 http://example.com/logo.png
擷取圖片 (包含 /i
前置字元):
https://example-com.cdn.ampproject.org/i/example.com/logo.png
由於 /i
前置字串後方沒有 /s
,因此 Google 會使用純文字 HTTP,而非透過傳輸層安全標準 (TLS) 從 example.com 擷取映像檔。
查詢參數範例
AMP 快取網址格式也可以在查詢字串中加入參數。
以下是含有參數的 HTTPS 範例:
https://example-com.cdn.ampproject.org/c/s/example.com/g?value=Hello%20World
Google AMP 快取更新
當使用者透過 Google AMP 快取要求取得 AMP 文件時,快取機制會自動要求更新,以便在快取內容後為下一位使用者提供最新內容。透過這個模型,AMP 文件的更新會自動套用快速又順暢,更新完成後,使用者會看到更新的版本。
快取遵循「s 過時-re-revalidate」模型。系統會使用來源的快取標頭 (例如 Max-Age
) 來提示特定文件或資源是否過時。當使用者對過期的要求發出要求時,該項要求會擷取新的副本,以便下一個使用者取得最新內容。
為了限制發布商網站產生的負載量,Google AMP 快取會將至少 15 秒的文件更新時間,以及任何資源至少 1 分鐘更新。請注意,由於我們會調整快取,以便在發布商網站與新鮮程度和負載之間取得最佳平衡,因此這些數字日後可能會改變。
快取最佳化和修改
Google AMP 快取會執行最佳化調整和修改,例如:
- 驗證內容是否確實為 AMP 格式,並符合所有 AMP 成效目標。
- 快取圖片和字型,以及 AMP 文件。
- 限制圖片尺寸上限,以免瀏覽器記憶體問題或回應不良。
- 多項轉換作業,透過
amp-img
標記提高圖片傳送效率,例如:
- 移除看不見或難以辨識的資料,例如特定中繼資料。
- 在使用支援 WebP 的瀏覽器中,將圖片轉換成小型和行動裝置相容性的圖片格式,例如將 GIF、PNG 和 JPEG 格式的圖片轉換為 WebP。
- 如果要求包含 Save-Data 標頭,則可以將圖片轉換成較低畫質。
- 產生替代大小的版本並新增
srcset
屬性,以支援提供回應式大小的圖片。
- 透過安全的頻道 (HTTPS) 提供服務,並使用最新的網路通訊協定 (SPDY、HTTP/2)。
- 對 AMP 文件進行清理,以免 HTML 標記錯誤、註解等錯誤而發生 XSS 攻擊。
進行上述轉換時,Google AMP 快取會忽略「Cache-Control: no-transform」標頭。
HTML 清理
Google AMP 快取會將所有文件改寫為正規化作業。例如:
- 系統會移除所有 HTML 註解。
- 標記和屬性名稱已縮短。
- 屬性值會持續加上引號並逸出。
- 除了 HTML5 void 元素之外,所有標記都會關閉。
- 標記中的空白字元會被移除。
- 文字會逸出。
- 使用 UTF-8 對等字元簡化編碼的文字字元。
- 只能在
body
中的元素會移至 body
。
- 對外連結是絕對的,因此當文件是透過 Google AMP 快取來源 (而非發布商來源) 提供時,會一直維持有效狀態。
Google AMP 快取會在瀏覽器中加入各種預先擷取提示代碼,協助您提早載入資源。例如,<link href='https://fonts.googleapis.com/css?family=Lato' rel='stylesheet’>
變更為:
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
<link href="https://fonts.gstatic.com" rel="dns-prefetch preconnect">
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2023-09-01 (世界標準時間)。
[null,null,["上次更新時間:2023-09-01 (世界標準時間)。"],[[["\u003cp\u003eGoogle AMP Cache delivers cached copies of valid AMP content for a faster user experience.\u003c/p\u003e\n"],["\u003cp\u003eUtilize the AMP Cache URL format to access content directly from the cache, ensuring automatic updates with each user access.\u003c/p\u003e\n"],["\u003cp\u003eThe Google AMP Cache optimizes and modifies content, including image transformations, security enhancements, and HTML sanitization, to improve delivery and performance.\u003c/p\u003e\n"],["\u003cp\u003eThe cache employs a "stale-while-revalidate" model, using origin caching headers and automatic updates to balance content freshness with publisher site load.\u003c/p\u003e\n"]]],["The Google AMP Cache stores and serves cached AMP content for fast user experiences. Accessing content via the AMP Cache URL format triggers automatic updates. The format includes a subdomain, content type (`c`, `i`, or `r`), optional `s` for TLS, and the content's URI. Content is considered fresh for at least 15 seconds (documents) or 1 minute (resources) before being revalidated. The cache optimizes content, such as images and documents, by validating AMP format, applying various transformations, and sanitizing HTML, for efficient and secure delivery.\n"],null,["# Overview\n\nThe Google AMP Cache serves cached copies\nof valid AMP content published to the web.\nServe content directly from the Google AMP Cache\nto provide a fast user experience.\n\n\nTo take advantage of the Google AMP Cache,\nan AMP URL must be accessed directly from the cache\nusing the AMP Cache URL format.\nEach time a user accesses AMP content from the cache,\nthe content is automatically updated,\nand the updated version is served to the next user once the content has been cached.\n\nAMP Cache URL format\n--------------------\n\n\nThe AMP Cache URL format consists of the following components:\n\n| Component | Description |\n|----------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Subdomain name | Subdomains created by the Google AMP Cache will be human-readable when character limits and technical specs allow, and will closely resemble the publisher's own domain. When possible, the Google AMP Cache will create each subdomain by: 1. Converting the AMP document domain from IDN (Punycode) to UTF-8. 2. Replacing every \"-\" (dash) with \"--\"(2 dashes). 3. Replacing every \".\" (dot) with a \"-\" (dash). 4. Converting back to IDN (Punycode). For example, `pub.com` will map to `pub-com.cdn.ampproject.org`. Where technical limitations prevent a human readable subdomain, a one-way hash will be used instead. |\n| Content type | The content type is one of the following: 'c' for an AMP HTML document, 'i' for an image, or 'r' for a resource such as a font. The Google AMP Cache returns a 404 error for resources that do not match these content types (see the [core error](/amp/cache/reference/errors/core_errors#NOT_FOUND)). |\n| Optional 's' | If present, requires that Google fetch the content from the origin using TLS (secure HTTPS). If the 's' is not present, then content gets fetched from the origin using plain HTTP. |\n| URI | URI of the content to be fetched. The URI cannot contain a scheme; that is, no \\`http://\\` or \\`https://\\`. |\n\n| **Note:** Use the [AMP URL API](/amp/cache/reference/acceleratedmobilepageurl/rest/v1/ampUrls/batchGet), to match URLs to corresponding AMP URLs and serve the AMP versions instead (see [Link to AMP Content](/amp/cache/use-amp-url)).\n\n### Finding the subdomain name\n\nTypically, the subdomain name for a Google AMP Cache URL will be a human-readable conversion of\nthe original URL using the steps outlined above. However, because there are circumstances where\nthis may not be true, the best way to retrieve Google AMP Cache URLs for production-ready\napplications is to use the [Google AMP Cache URL API](/amp/cache/use-amp-url).\n\nFor non-production situations, to determine what subdomain name the Google AMP Cache generates,\ntry out the [Using the Google AMP Cache](https://amp.dev/documentation/examples/guides/using_the_google_amp_cache/)\ninteractive tool on [amp.dev](https://amp.dev/documentation/examples/guides/using_the_google_amp_cache/).\n\n### Example requesting document using TLS\n\nRequest for an AMP HTML document (specified with the `/c` prefix)\nfetched from `https://example.com/amp_document.html`: \n\n```\nhttps://example-com.cdn.ampproject.org/c/s/example.com/amp_document.html\n```\n\nBecause `/s` follows the `/c` prefix,\nthe document will be fetched from example.com using TLS.\n\n### Example requesting image using plain HTTP\n\nRequest for an image (specified with the `/i` prefix)\nfetched from `http://example.com/logo.png`: \n\n```\nhttps://example-com.cdn.ampproject.org/i/example.com/logo.png\n```\n\nBecause there's no `/s` following the `/i` prefix,\nGoogle fetches the image from example.com using plain HTTP,\nnot HTTP over TLS.\n\n### Query parameter example\n\nThe AMP Cache URL format can also include parameters in the query string.\nThe following is an HTTPS example with parameters:\n`https://example-com.cdn.ampproject.org/c/s/example.com/g?value=Hello%20World`\n\nGoogle AMP Cache updates\n------------------------\n\nWhen a user requests an AMP document from the Google AMP Cache,\nthe cache automatically requests updates in order to be able\nto serve fresh content for the next user once the content has been cached.\nWith this model, updates to AMP documents propagate automatically and quickly;\nfew users will see the non-updated version after your update.\n\n\nThe cache follows a \"stale-while-revalidate\" model.\nIt uses the origin's caching headers, such as `Max-Age`,\nas hints in deciding whether a particular document or resource is stale.\nWhen a user makes a request for something that is stale,\nthat request causes a new copy to be fetched, so that the next user gets fresh content.\n\n\nTo limit the amount of load it generates for publisher sites,\nthe Google AMP Cache considers any document fresh for at least 15 seconds,\nand any resource fresh for at least 1 minute.\nNote that those numbers may change in the future,\nas we tune the cache for optimum balance between freshness and load on publisher sites.\n\nCache optimizations and modifications\n-------------------------------------\n\nThe Google AMP Cache performs optimizations and modifications,\nsuch as the following:\n\n- Validates content is truly in AMP format, meeting all AMP performance goals.\n- Caches images and fonts in addition to AMP documents.\n- Limits maximum image dimensions to prevent browser memory issues and poor responsiveness.\n- Various transformations to improve the delivery efficiency of images via the `amp-img` tag, such as:\n - Removal of data that is invisible or difficult to see, such as certain metadata.\n - Conversion of images to smaller and mobile-friendlier image formats, such as converting GIF, PNG, and JPEG format images to WebP in browsers that support WebP.\n - Transformation of the image to a lower quality if the request includes the Save-Data header.\n - Generation of alternatively sized versions and adding `srcset` attributes to support delivery of responsively sized images.\n- Serves over a secure channel (HTTPS) and uses the latest web protocols (SPDY, HTTP/2).\n- Sanitizes AMP documents to prevent XSS attacks based on incorrectly closed HTML tags, comments, and more.\n\n\nIn making the above transformations,\nthe Google AMP Cache disregards the \"Cache-Control: no-transform\" header.\n\nHTML sanitization\n-----------------\n\n\nThe Google AMP Cache rewrites all documents to normalize parsing.\nExamples include:\n\n- All HTML comments are stripped.\n- Tag and attribute names are lowercased.\n- Attribute values are consistently quoted and escaped.\n- All tags are closed, except for HTML5 void elements.\n- Whitespace inside tags is stripped.\n- Text is escaped.\n- Encoded text characters are simplified, using UTF-8 equivalent characters.\n- Elements that can only be in the `body` get moved into the `body`.\n- Outbound links are made absolute so that they continue to work when the document is served from the Google AMP Cache origin instead of the publisher origin.\n\nInsert prefetch tags\n--------------------\n\nThe Google AMP Cache adds various prefetch hint tags for browsers\nto assist in loading resources earlier.\nFor example,\n`\u003clink href='https://fonts.googleapis.com/css?family=Lato' rel='stylesheet'\u003e`\nchanges to: \n\n```text\n\u003clink href=\"https://fonts.googleapis.com/css?family=Lato\" rel=\"stylesheet\"\u003e\n\u003clink href=\"https://fonts.gstatic.com\" rel=\"dns-prefetch preconnect\"\u003e\n```"]]