Serve different JS files, depending on browser support?

Mark S. Miller erights at
Thu Sep 5 06:40:54 PDT 2013

On Thu, Sep 5, 2013 at 4:27 AM, Axel Rauschmayer <axel at> wrote:

> In principle, you could serve different files to different browsers:
> – Browser supports ES6 => serve an ES6 .js file
> – Otherwise => compile ES6 to ES5 (or ES3)
> What is the best way to do this?
> – Browsers tell servers their level of ECMAScript support?
> – You can do a feature detection in JS and then load modules
> conditionally? But that seems like a more complicated solution. I’m not
> even sure how I would implement the detection part.

That's how Caja currently deploys. If feature detection <>
says the browser adequately implements ES5, we deploy the (approximately no
translation) SES-on-ES5 implementation <>.
Otherwise we fall back to Caja's ES5-to-ES3 translator (ES5/3) and runtime <

You can see the effect by visiting <> and watching
the menu whose state starts in "Autodetect Mode" and then switches to
either "ES5 Mode" or "ES5/3 Mode" depending on this autodetection decision.
It is a menu so that you can also override this by manually forcing the
choice you'd like.

As you can see from <>,
the autodetection is tricky because browsers only gradually implemented
more and more of ES5 and few implement it completely. But the autodetection
has to judge when they implement enough to be considered an ES5 browser. I
expect the same will be true for the ES5 to ES6 transition.

You can also see the outcome of the individual tests used in this
autodetection at <>,
or by watching the console when visiting <>.

> --
> Dr. Axel Rauschmayer
> axel at
> home:
> twitter:
> blog:
> _______________________________________________
> es-discuss mailing list
> es-discuss at

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list