11

I have been determining the version of the IE Trident engine using javascript conditional compilation:

var ieVersion = undefined;
/*@cc_on
   ieVersion = Math.floor(@_jscript_version);
@*/

This worked fine for IE8, 9 and 10. In IE11, the conditionally-commented block does not execute, unless I use the F12 dev tools to emulate IE10 (in which case it returns the correct value, 11).

This is confusing, since the MSDN page on conditional compilation specifies that it applies to Internet Explorer 11. (UPDATE 2015-02-03: this page has since been updated to explicitly state that its content does not apply to IE11 in standards mode.) I've not found any information online to suggest that IE11 should not support conditional comments.

Does anyone have any information about this? Can anyone reproduce this behaviour in IE11?


Edit: the relevance of this is in IE's <audio> support. I have a web app that requires playback of around 50 short (~1sec) audio files, which should be played in a (pseudo-)random order, and individually after user interaction. The problems are various:

  • IE9 has an undocumented limit of 41 audio elements (whether declared in HTML or as JS objects). All subsequent audio files silently fail to load and play. (Each of the 41 elements can have its source re-assigned, but every second re-assignment also fails silently. I would love to see the code behind these bugs...)
  • IE10 and IE11 "stutter" when playing short sounds: they play a fraction of a second, then pause, then continue on. The effect to the end-user is that the audio is unintelligible. (The audios have preload="auto" and report a non-zero buffer.)

Naturally there's no practical way to feature-detect these issues, hence the browser-detect. I generally feel user-agent sniffing is too dicey for production code; the @cc_on technique seemed more robust.

My workaround for IE9 is to serialise the app state to sessionStorage after the 25th sound, then reload the page and deserialise.

In IE10/11, my workaround is to play the last 90% of the audio at 0 volume, which seems to force IE to actually buffer the file.

Jeremy
  • 2,642
  • 18
  • 36
  • 2
    IE11 removed support for conditional compilation. – Qantas 94 Heavy Dec 05 '13 at 05:30
  • 1
    @Qantas94Heavy can you provide a source for that? As I say in the question, MSDN is telling me *explicitly* that IE11 has support for conditional compilation. Hence, confusion. – Jeremy Dec 05 '13 at 05:33
  • That's just from anecdotal experience, don't have a source for that :( – Qantas 94 Heavy Dec 05 '13 at 05:33
  • 1
    @Qantas94Heavy Conditional compilation !== Conditional comments. – Teemu Dec 05 '13 at 06:14
  • @Teemu: I'm well aware of that, but from what I can tell I've not been able to make `/*@cc_on*/` code work in IE11 standards mode. HTML conditional comments (i.e. ` – Qantas 94 Heavy Dec 05 '13 at 10:43
  • 3
    Strange, the official MS documentation clearly says that conditional compilation is available in every version of IE. Though I can't get even their exampple to work in IE11... Anyway, `ScriptEngineMajorVersion()` gives you the same result as `@_jscript_version`, no need for conditional compilation. This function is working in IE11 too. – Teemu Dec 05 '13 at 11:46
  • In the absence of a definitive answer, your best bet may be to assume that they're not longer available. Even if they somehow are available in IE11, they're a non-standard feature so which means there's a good chance they will be removed in the future (IE12?) so even if you get it working now you'll still have to deal with it not working in the future. Therefore, my suggestion would be to try to find an alternative solution. What do you use the version number for -- do you actually need to detect the IE version or could you achieve you goal some other way (eg feature detection) instead? – Spudley Dec 06 '13 at 09:22
  • @Spudley I agree. I added an explanation of the need for browser-detect to the question. For now I'm just using UA-based detection. – Jeremy Dec 08 '13 at 22:13
  • 1
    Just a random thought, but maybe you could concatenate all the files into a single ` – Stephen Thomas Dec 08 '13 at 23:12
  • @StephenThomas good thought; we went with individual files because the "monolithic audio" technique is difficult to manage on iOS devices and chrome-mobile where preloading is not allowed. Probably in hindsight the monolith would have been the better option though. – Jeremy Dec 08 '13 at 23:21

1 Answers1

13

Yes, IE11 has removed javascript conditional compilation


The google search linked in the question returns this question as its third result, after two MSDN pages also linked above. This establishes the lack of a better source, so I think this question (including comments) should be considered the authoritative reference for the fact that Javascript conditional compilation is not available in IE11.

I have submitted feedback on the MSDN pages to the effect that they are incorrect.

Update 2015-02-03: MSDN now acknowledges that IE11 no longer supports @cc_on.


Some workarounds are as follows:

User-agent detection

 /\([^)]*Trident[^)]*rv:([0-9.]+)/.exec(ua)

will parse IE11's UA string and return the "revision number" at the end.

ScriptEngineMajorVersion() (thanks @Teemu)

 var tridentVersion = 
     typeof ScriptEngineMajorVersion === "function" ?
         ScriptEngineMajorVersion() : undefined

should evaluate correctly on all browsers, but we can't guarantee ScriptEngineMajorVersion will not be dropped without warning just as conditional compilation has been.


Thanks to all commenters.

Jeremy
  • 2,642
  • 18
  • 36