4

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

<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.

toomanyairmiles
  • 6,465
  • 8
  • 43
  • 71

4 Answers4

5

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.

Guffa
  • 687,336
  • 108
  • 737
  • 1,005
  • 1
    agreed but note: The CMS the company uses I work for reparses all empty tags to a self closing tag. :( in those exceptional cases putting a dummy in the tag can be useful. – Caspar Kleijne Mar 23 '11 at 11:42
  • @Caspar Kleijne: That's a good point. That may also be the reason why you would ever see a script tag with both a `src` attribute and content. – Guffa Mar 23 '11 at 12:55
  • @Caspar - you hit the nail on the head, turns out a problem with documentam is the reason for the comments being there – toomanyairmiles Mar 23 '11 at 14:30
4

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

Teo Klestrup Röijezon
  • 5,097
  • 3
  • 29
  • 37
0

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.

Czechnology
  • 14,832
  • 10
  • 62
  • 88
  • noscript is a cop out for people who haven't used progressive enhancement – Quentin Mar 23 '11 at 11:33
  • @David Dorward, what do you mean with that? – Czechnology Mar 23 '11 at 11:55
  • If you do it right then you have a page that works without JS, works better with JS on an older browser and works even better with JS on a newer browser. If you are using noscript, then best case is you aren't dealing well with the middle case, and worse case you are using it to tell people that their browser configuration is wrong (which it isn't). – Quentin Mar 23 '11 at 11:58
  • Maybe I didn't explain my point well. There should always be a backup solution on the server-side (not like the stupid facebook). But it still is a good thing to use noscript to tell the user without JS that he might be missing some features. – Czechnology Mar 23 '11 at 13:33
0

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.

Community
  • 1
  • 1
Scott Stafford
  • 43,764
  • 28
  • 129
  • 177
  • It is hurting load speed a little bit, although that is almost nothing. – Teo Klestrup Röijezon Mar 23 '11 at 11:26
  • This is only targeting modern browsers IE7 and up, but so far as I'm aware this would only affect browsers of the < IE5 generation? – toomanyairmiles Mar 23 '11 at 11:26
  • @toomanyairmiles: IE 2 is the last version of IE for the HTML comments inside the ` – Tim Down Mar 23 '11 at 11:53