开发者

is <script><!--//--></script> useful anymore

开发者 https://www.devze.com 2023-02-19 18:21 出处:网络
I\'m reviewing some html produced by an overseas development shop for us. They are using comments inside their external script loading tags - so far as i\'m aware this was only useful for very old jav

I'm reviewing some html produced by an overseas development shop for us. They are using comments inside their external script loading tags - so far as i'm aware this was only useful for very old javascript unaware browsers who used to render the scripts as text - is there any modern purpose for this or is it now completely redundant?

<script type="text/javascript" src="path/to/file.js"><!--//--></script>  

Thanks in advance

//Update after comments below: It turns out that the comments were hacking a problem in the Content Management System where it would render the tag as

&开发者_开发技巧lt;script type="text/javascript" src="path/to/" />

without the comments present - so the answer is that they nolonger have any use in general web development but there are some specific circumstances where they may be useful. Kudos to Caspar Kleijne for pointing this out.


No, it's not useful any more.

It was used way back when there still existed browsers that were shipped before Javascript existed. Nowadays every browser is aware of the existance of Javascript, even if they don't support it.

If someone still would have such an ancient browser isntalled, your page will look so terribly crappy in it that it doesn't make any difference.


Since you are including it from an external file, there should be no use at all for it.


This always depends on your target group. You could check your site's stats to see if there's a significant number of people using some old old browsers and then decide. It's rather improbable you'll find many, if any.

Personally, I don't comment out my JavaScript code.

But on a sidenote - using <noscript> is still important, maybe now more than ever in the time of ajax-driven sites.


It isn't necessary going forward and is often left off, though it may be an attempt at XHTML standardization, where CDATA is typically used. This question has lots more information: When is a CDATA section necessary within a script tag?

Whether intended for XHTML or for old-browser support, it isn't hurting anything, though it almost definitely not helping. It could help to support some archaic browsers, but if you're not testing against those specifically, your site won't work properly anyhow. Leave it off unless you are using XHTML.

0

精彩评论

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

关注公众号