非同步載入廣告代碼
總覽
這項稽核可確保系統以非同步方式載入廣告代碼程式庫指令碼。
根據預設,JavaScript 執行作業是採取同步方式。這表示系統遇到指令碼時,在指令碼下載、剖析及執行完成之前,其他內容都無法載入。選擇採用非同步執行作業可以防止這個問題,因為瀏覽器能在背景載入指定的指令碼,並繼續處理其他資源。這可讓您的網頁在指令碼載入期間保持回應,並縮短載入所有重要元件所需的時間。
建議
在指令碼標記定義中加入 async 屬性。例如:
AdSense
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
AdSense (自動廣告)
<script async data-ad-client="ca-pub-xxxxxxxxxxxxxxxx" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
Google 發布商廣告代碼
<script async src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"></script>
系統支援下列廣告代碼程式庫指令碼:
廣告代碼程式庫 |
指令碼 |
AdSense |
pagead2.googlesyndication.com/pagead/js/adsbygoogle.js
pagead2.googlesyndication.com/pagead/show_ads.js
|
Google 發布商廣告代碼 |
googletagservices.com/tag/js/gpt.js
securepubads.g.doubleclick.net/tag/js/gpt.js
|
開始使用 Google 發布商廣告代碼
GPT 請求模式和非同步顯示模式
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2024-10-15 (世界標準時間)。
[null,null,["上次更新時間:2024-10-15 (世界標準時間)。"],[[["This audit verifies if ad tag library scripts are loaded asynchronously to improve page performance."],["Asynchronous loading allows the browser to load other content while the script loads in the background, preventing delays and improving user experience."],["To enable asynchronous loading, include the `async` attribute within the `\u003cscript\u003e` tag when implementing ad tags like AdSense and Google Publisher Tag."],["Synchronous loading, where the browser waits for the script to fully load before proceeding, can negatively impact page load times and overall performance."]]],["To optimize page load times, ad tag library scripts should load asynchronously. This is achieved by including the `async` attribute within the `\u003cscript\u003e` tag. Asynchronous loading allows the browser to continue loading other page content while the script downloads and executes in the background. Supported ad tag libraries include AdSense and Google Publisher Tag, with specific script URLs like `pagead2.googlesyndication.com/pagead/js/adsbygoogle.js` and `securepubads.g.doubleclick.net/tag/js/gpt.js` needing the `async` attribute.\n"]]