Thursday, April 22, 2010

Why don't browsers provide a generic VM instead of just Javascript?

Why is it that the only way to make a web page scriptable and dynamic is to use Javascript?

I'm sure there are multiple historical reasons. But as browsers become less and less simple document viewers and more and more a computing platform unto themselves, Javascript is being stretched far beyond its intended design. The fact that modern browsers such as Chrome can squeeze the performance they do out of it is in itself remarkable.

However, everyone would be better served if browsers provide a generic virtual machine, with public APIs for accessing the DOM, etc. Instead of providing Javascript to a webpage, you could provide bytecode, compiled from any language, which would happily run in a nice sandboxed environment. It'd be a lot cleaner, and a lot faster. Of course, browsers would still provide legacy support for compiling and running provided Javascript as the new bytecode.

And no, Java  applets don't cut it. For one thing, they are a third party plugin. For another, for most of their history, they've sucked. Most of all, they have a strong visual signature, whereas ideally a browser VM would be entirely unobtrusive - the goal would be to fill the role of Javascript, not Java applets or Flash or Silverlight.

0 comments: