HTML链接预紧力无法正常工作
我在下面添加了用于AdSense的链接预加载:
<link rel="preconnect" href="https://pagead2.googlesyndication.com" crossorigin="anonymous">
<link rel="dns-prefetch" href="https://pagead2.googlesyndication.com">
<link rel="preload" as="script" href="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-6815942738114816" crossorigin="anonymous">
Google Analytics(Analytics)4 /Google Tag Manager
<!--Google Tag Manager / Google Analytics-->
<link rel="preconnect" href="https://www.googletagmanager.com">
<link rel="dns-prefetch" href="https://www.googletagmanager.com">
<link rel="preconnect" href="https://analytics.google.com">
<link rel="dns-prefetch" href="https://analytics.google.com">
<link rel="preload" as="script" href="https://www.googletagmanager.com/gtag/js?id=G-PMCHMHK7J9">
for Adsense的标签下面是我的标记中的脚本标签:
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=MY_CLIENT_ID" crossorigin="anonymous"></script>
Google Analytics(Google Analytics)4我在标记中有以下标签:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-PMCHMHK7J9"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', 'G-PMCHMHK7J9');
</script>
但是此设置为NON' T似乎可以正常工作,并且在浏览器中运行时,Adsense和Google Analytics(分析)脚本都没有预加载。
AdSense脚本的响应标题下方:
access-control-allow-origin: *
cache-control: private, max-age=3600
content-type: text/javascript; charset=UTF-8
cross-origin-resource-policy: cross-origin
expires: Tue, 07 Jun 2022 12:32:56 GMT
timing-allow-origin: *
vary: Accept-Encoding
vary: Origin
x-content-type-options: nosniff
x-xss-protection: 0
Google标签管理器的响应标题下方:
access-control-allow-credentials: true
access-control-allow-headers: Cache-Control
access-control-allow-origin: *
cache-control: private, max-age=900
content-encoding: br
content-length: 70509
content-type: application/javascript; charset=UTF-8
cross-origin-resource-policy: cross-origin
date: Tue, 07 Jun 2022 12:32:56 GMT
expires: Tue, 07 Jun 2022 12:32:56 GMT
server: Google Tag Manager
strict-transport-security: max-age=31536000; includeSubDomains
vary: Accept-Encoding
x-xss-protection: 0
如果我缺少任何东西,请任何人指导。
谢谢
I have added below link preload for Adsense:
<link rel="preconnect" href="https://pagead2.googlesyndication.com" crossorigin="anonymous">
<link rel="dns-prefetch" href="https://pagead2.googlesyndication.com">
<link rel="preload" as="script" href="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-6815942738114816" crossorigin="anonymous">
And below preload tags for Google Analytics 4 /Google Tag Manager
<!--Google Tag Manager / Google Analytics-->
<link rel="preconnect" href="https://www.googletagmanager.com">
<link rel="dns-prefetch" href="https://www.googletagmanager.com">
<link rel="preconnect" href="https://analytics.google.com">
<link rel="dns-prefetch" href="https://analytics.google.com">
<link rel="preload" as="script" href="https://www.googletagmanager.com/gtag/js?id=G-PMCHMHK7J9">
For Adsense I have below script tag in my markup:
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=MY_CLIENT_ID" crossorigin="anonymous"></script>
And for Google Analytics 4 I have below tags in my markup:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-PMCHMHK7J9"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', 'G-PMCHMHK7J9');
</script>
But this setup doesn't seems to work and when running in browser both Adsense and Google Analytics scripts are not preloaded.
The Adsense Script has below response headers:
access-control-allow-origin: *
cache-control: private, max-age=3600
content-type: text/javascript; charset=UTF-8
cross-origin-resource-policy: cross-origin
expires: Tue, 07 Jun 2022 12:32:56 GMT
timing-allow-origin: *
vary: Accept-Encoding
vary: Origin
x-content-type-options: nosniff
x-xss-protection: 0
And Google tag Manager has below Response Headers:
access-control-allow-credentials: true
access-control-allow-headers: Cache-Control
access-control-allow-origin: *
cache-control: private, max-age=900
content-encoding: br
content-length: 70509
content-type: application/javascript; charset=UTF-8
cross-origin-resource-policy: cross-origin
date: Tue, 07 Jun 2022 12:32:56 GMT
expires: Tue, 07 Jun 2022 12:32:56 GMT
server: Google Tag Manager
strict-transport-security: max-age=31536000; includeSubDomains
vary: Accept-Encoding
x-xss-protection: 0
Can anyone please guide if I am missing anything.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在加载脚本 https://www.googletagmanager.com/gtag/gtag/js/gtag/js js ?通过这样做,您无需帮助浏览器执行预紧力。 Google Analytics(分析)脚本已加载而没有明显的优先级。即使您尝试使用CDN使用103点击中,也不会给您带来重大结果。前连接适用于其他脚本中调用的脚本。例如,在Google Adsense中,加载主脚本时,浏览器会加载其他脚本(分析,本地广告脚本),并预处理这些脚本将使您在慢速Internet上获得一些利润。
You are loading the script https://www.googletagmanager.com/gtag/js?id=G-PMCHMHK7J9 together with the HTML. By doing so, you are not helping the browser to perform a preload. The Google Analytics script is loaded without obvious priority. Even if you try to use a 103 early hit with a CDN, it will not give you a significant result. Preconnect works well for scripts that are called inside other scripts. For example, in Google Adsense, when loading the main script, the browser loads additional scripts (analytics, local ad script) and preconnecting these scripts would give you some profit on slow internet.