双脚本标记中有任何值吗?

编程入门 行业动态 更新时间:2024-10-28 18:24:07
本文介绍了双脚本标记中有任何值吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经在几段代码中看到了这一点,并且我不想假设"它并不重要,但这是Google Analytics(分析)代码的副本:

I've seen this in a few pieces of code and I didn't want to "assume" it was unimportant but this is a copy of the Google Analytics code:

<script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "ssl." : "www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics/ga.js' type='text/javascript'%3E%3C/script%3E")); </script> <script type="text/javascript"> try { var pageTracker = _gat._getTracker("UA-xxxxxx"); pageTracker._trackPageview(); } catch(err) {} </script>

您会注意到有两个打开/关闭脚本标签.有什么理由将代码位封装在两个不同的脚本标签中是有好处的?我的第一个反应就是简单地删除冗余.

You'll notice there are two open / close script tags. Is there any reason why encapsulating the code bits in two different script tags is beneficial? My first reaction would be simply to remove the redundancy.

推荐答案

第一块将< script> 标记写入页面.我认为,如果代码全部放在一个块中,则不能保证在执行第二部分代码之前会先加载写入的< script> .

The first block writes a <script> tag to the page. I think if the code was all in one block there would be no guarantee the written <script> would be loaded before the second part of the code executed.

通过使用两个块,写入的< script> 将在第二个块执行之前加载(包含 _gat 对象).

By using two blocks, the written <script> will load (which contains the _gat object) before the second block executes.

更多推荐

双脚本标记中有任何值吗?

本文发布于:2023-10-23 04:16:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1519750.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中有   双脚   标记

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!