Tải tập lệnh quảng cáo tĩnh
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Tổng quan
Quá trình kiểm tra này kiểm tra xem tập lệnh quảng cáo có đang được chèn vào trang hay không.
Các tài nguyên khác trên trang có thể trì hoãn việc tìm nạp và tải tệp được chèn
vì các tập lệnh này sẽ làm trì hoãn việc tải quảng cáo. Trong một số trường hợp,
tập lệnh có thể không được tìm nạp, khiến quảng cáo không được tải tất cả
khi kết hợp cùng nhau.
Đề xuất
Tải tập lệnh qua các thẻ tập lệnh không đồng bộ để cải thiện tốc độ. Trình quét tải trước trình duyệt
có thể tìm nạp các thẻ tập lệnh sớm hơn, ngay cả khi các tài nguyên chặn hiển thị đang chặn
thực thi tập lệnh.
Không chính xác |
<script>
var el = document.createElement('script');
el.src = 'https://securepubads.g.doubleclick.net/tag/js/gpt.js';
var node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(el, node);
</script>
|
Đúng |
<script async src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"></script>
|
Xác định nguồn tập lệnh quảng cáo được chèn
Đôi khi, bạn có thể không rõ tập lệnh quảng cáo sẽ được chèn vào trang như thế nào
hay thậm chí là dữ liệu nào cũng được đưa vào. Ví dụ: khi kiểm tra nguồn
của trang sau khi được tải, thẻ tập lệnh đã được chèn có thể xuất hiện
không thể phân biệt với thẻ được tải tĩnh.
Trong những trường hợp này, hãy sử dụng thẻ Mạng trong Công cụ của Chrome cho nhà phát triển để xác định nguồn
tập lệnh quảng cáo được chèn.
- Mở Công cụ cho nhà phát triển bằng cách nhấn
Control+Shift+J
hoặc Command+Option+J
(máy Mac).
- Chuyển đến thẻ Mạng.
- Nếu chưa hiển thị, hãy nhấp vào Bộ lọc
Nhấn phím
để mở thanh bộ lọc và nhập
tên của tập lệnh bị gắn cờ bị quá trình kiểm tra này gắn cờ vào hộp văn bản.
- Nếu tiêu đề bảng chưa xuất hiện, hãy nhấp chuột phải vào tiêu đề bảng bất kỳ rồi chọn
Trình khởi tạo để đưa cột Trình khởi tạo vào yêu cầu mạng
bảng thác nước.
- Tải lại trang để thu thập lưu lượng truy cập mạng.

Như trong ảnh chụp màn hình ở trên, cột trình khởi tạo sẽ chứa thông tin
nguồn của tập lệnh được đề cập. Bạn có thể nhấp vào đường liên kết nguồn để
chuyển thẳng đến mã chịu trách nhiệm phát hành yêu cầu tập lệnh quảng cáo, hoặc
hãy di chuột qua đường liên kết nguồn để xem tất cả các lệnh gọi dẫn đến yêu cầu.
Quá trình kiểm tra này hoạt động dựa trên danh sách cho phép gồm các tập lệnh quảng cáo được xác định là an toàn
để tải tĩnh. Danh sách hiện tại là:
Thư viện |
(Các) tập lệnh |
AdSense |
pagead2.googlesyndication.com/pagead/js/adsbygoogle.js
|
Dịch vụ dành cho nhà xuất bản của Amazon |
amazon-adsystem.com/aax2/apstag.js
|
Bên đặt giá thầu trực tiếp Criteo |
static.criteo.net/js/*/publishertag.js
|
Thẻ nhà xuất bản của Google |
googletagservices.com/tag/js/gpt.js
securepubads.g.doubleclick.net/tag/js/gpt.js
|
Index Exchange |
js-sec.indexww.com/ht/p/*.js
|
Can thiệp vào document.write()
"Tập lệnh không đồng bộ" được chèn tập lệnh bị coi là gây hại
Tăng tốc các đoạn mã không đồng bộ
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2024-08-22 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2024-08-22 UTC."],[[["\u003cp\u003eThis audit identifies ad scripts injected into the page that may delay or prevent ad loading.\u003c/p\u003e\n"],["\u003cp\u003eUse async script tags to improve loading speed, enabling the browser to fetch scripts earlier.\u003c/p\u003e\n"],["\u003cp\u003eIf the source of an injected ad script is unclear, Chrome DevTools' Network tab can be used to identify it.\u003c/p\u003e\n"],["\u003cp\u003eA list of safe-to-load ad scripts is provided, including those from AdSense, Amazon, Criteo, Google Publisher Tag, and Index Exchange.\u003c/p\u003e\n"]]],["Ad scripts injected into a page can delay or prevent ad loading. To improve speed, load scripts using `async` script tags, allowing the browser to fetch them earlier. To identify injected scripts, use Chrome DevTools' Network tab: filter by the script name and enable the \"Initiator\" column to find the source. The document provides examples of correct and incorrect code for loading scripts and includes a list of ad scripts from AdSense, Amazon, Criteo, Google Publisher Tag, and Index Exchange.\n"],null,["# Load ad scripts statically\n\nOverview\n--------\n\nThis audits checks whether or not ad scripts are being injected into the page.\nOther resources on the page may delay the fetching and loading of injected\nscripts, which will in turn delay the loading of ads. In some situations these\nscripts may not be fetched at all, preventing ads from being loaded all\ntogether.\n\nRecommendations\n---------------\n\nLoad scripts via async script tags to improve speed. The browser preload scanner\ncan fetch script tags earlier, even if render blocking resources are blocking\nthe script execution.\n\n|---------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| **Incorrect** | ```html \u003cscript\u003e var el = document.createElement('script'); el.src = 'https://securepubads.g.doubleclick.net/tag/js/gpt.js'; var node = document.getElementsByTagName('script')[0]; node.parentNode.insertBefore(el, node); \u003c/script\u003e ``` |\n| **Correct** | ```html \u003cscript async src=\"https://securepubads.g.doubleclick.net/tag/js/gpt.js\"\u003e\u003c/script\u003e ``` |\n\n### Identify the source of injected ad scripts\n\nSometimes it may not be obvious how an ad script is being injected into a page,\nor even that it's being injected at all. For example, when examining the source\nof a page after it's loaded, a script tag that has been injected may appear\nindistinguishable from a tag that was loaded statically.\n\nIn these cases, use the Network tab in Chrome DevTools to determine the source\nof injected ad scripts.\n\n1. Open DevTools by pressing `Control+Shift+J` or `Command+Option+J` (Mac).\n2. Navigate to the **Network** tab.\n3. If not already visible, click **Filter** to open the filter bar and type the name of the script flagged by this audit into the text box.\n4. If not already visible, right-click on any table header and select **Initiator** to include the Initiator column in the network request waterfall table.\n5. Reload the page to capture network traffic.\n\nAs seen in the above screenshot, the initiator column will contain information\nabout the source of the script in question. You can click on the source link to\njump directly to the code responsible for issuing the ad script request, or\nhover over the source link to see all of the calls leading up to the request.\n\nMore information\n----------------\n\nThis audit operates against a allowlist of ad scripts which are known to be safe\nto load statically. The current list is:\n\n| Library | Script(s) |\n|---------------------------|--------------------------------------------------------------------------------------|\n| AdSense | `pagead2.googlesyndication.com/pagead/js/adsbygoogle.js` |\n| Amazon Publisher Services | `amazon-adsystem.com/aax2/apstag.js` |\n| Criteo Direct Bidder | `static.criteo.net/js/*/publishertag.js` |\n| Google Publisher Tag | `googletagservices.com/tag/js/gpt.js` `securepubads.g.doubleclick.net/tag/js/gpt.js` |\n| Index Exchange | `js-sec.indexww.com/ht/p/*.js` |\n\n[Intervening against document.write()](https://developers.google.com/web/updates/2016/08/removing-document-write) \n\n[Script-injected \"async scripts\" considered harmful](https://www.igvita.com/2014/05/20/script-injected-async-scripts-considered-harmful/) \n\n[Speeding Up Async Snippets](https://csswizardry.com/2022/10/speeding-up-async-snippets/) \n[View audit source](https://github.com/googleads/publisher-ads-lighthouse-plugin/tree/HEAD/lighthouse-plugin-publisher-ads/audits/script-injected-tags.js) [Improve this article](https://github.com/googleads/publisher-ads-lighthouse-plugin/tree/HEAD/docs/audits/script-injected-tags.md) [Report an issue](https://github.com/googleads/publisher-ads-lighthouse-plugin/issues/new?labels=documentation&template=documentation-feedback.md&title=Documentation+feedback%3A+script-injected-tags.md)\n\n\u003cbr /\u003e"]]