【问题标题】:Why should Tealium utag script be added to the page dynamically?为什么需要将 Tealium utag 脚本动态添加到页面中?
【发布时间】:2020-10-08 18:45:41
【问题描述】:

我遇到了建议将标签包含在以下 sn-p 代码中的 tealium utag.js 文档。基本上,它会创建一个异步脚本标签并将其插入到文档的第一个脚本标签之前。

<script type="text/javascript">
  // some setup needed for Tealium utag.js to work properly
</script>
<!-- Tealium snippet to include utag.js -->
<script type="text/javascript">
  (function(a,b,c,d) {
      a='//tags.tiqcdn.com/utag/ACCOUNT/PROFILE/ENVIRONMENT/utag.js';
      b=document;c='script';d=b.createElement(c);d.src=a;
      d.type='text/java'+c;d.async=true;
      a=b.getElementsByTagName(c)[0];a.parentNode.insertBefore(d,a)})();
</script>

我想知道使用这个 sn-p 而不是直接将脚本包含在 DOM 中是否有任何优势/区别。

<script type="text/javascript">
  // some setup needed for Tealium utag.js to work properly
</script>
<!-- Include utag.js asynchronously -->
<script type="text/javascript" src="//tags.tiqcdn.com/utag/ACCOUNT/PROFILE/ENVIRONMENT/utag.js" async></script>

【问题讨论】:

    标签: javascript html tealium


    【解决方案1】:

    原因是推荐的方法与 100% 的浏览器兼容。大多数现代浏览器都支持异步选项,因此您可能可以安全地使用它,但您的访问者可能使用的是旧版浏览器。您可能需要谨慎行事,并确保您支持所有用户。

    https://caniuse.com/script-async

    【讨论】:

    • 在第一种方法中,脚本创建完全相同的
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多