开发者

Why does this javascript output using unescape and document.write? cache breaking? [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

What is the advantage of using unescape on document.write to load javascript?

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>

If the ga.js file chan开发者_开发技巧ges, will this cause any potential issues with browser cache? or will it always serve up the file fresh?


It means the code will work in XML / XHTML and HTML without having to mess with CDATA

See: What is the advantage of using unescape on document.write to load javascript?

Voted to close as duplicate.


It depends on server settings as to whether or not it will serve a fresh file.

As for why it writes the script tag dynamically, it's so that on secured pages (https pages) the script comes from a secure source.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜