使用 AMP URL API
簡介
AMP URL API 會針對指定的網址清單,擷取相符的 AMP 網址。應用程式可以使用此 API,以便在開啟外部連結時載入速度更快的 AMP,而非原始網址。
URL API 針對具有相符 AMP 版本的指定網址,傳回三種不同的網址
originalUrl
:未修改的原始網址。ampUrl
:AMP 版本的網址。cdnAmpUrl
:Google AMP Cache 中快取 AMP 版本的網址。
基於效能和安全考量,我們建議在顯示 AMP 內容時使用快取的 AMP 版本。
看看它是如何運作的
按下「執行」即可對 AMP URL API 執行即時查詢。變更輸入查詢內容並嘗試不同的網址。
<amp-iframe title="Performs a live query against the AMP URL API"
width="auto" height="645"
layout="fixed-height"
sandbox="allow-scripts allow-same-origin allow-popups"
allowfullscreen
frameborder="0"
src="/static/samples/files/amp-url-api.html">
<amp-img src="/static/samples/img/amp-url-api-placeholder.png"
layout="fixed-height"
height="645"
placeholder>
</amp-img>
</amp-iframe>
需要更多說明嗎?
如果這個頁面上的說明未能解答您的所有疑問,歡迎您與其他 AMP 使用者聯絡,討論您的確切使用情境。
前往 Stack Overflow 有未說明的特色功能嗎?AMP 專案非常鼓勵您的參與和貢獻!我們希望您能長期參與我們的開放原始碼社群,同時也歡迎您針對特別感興趣的問題提供一次性的貢獻。
在 GitHub 上編輯範例-
作者: @sebastianbenz