Hi everyone.
Forgive me if I sound Naive, but JavaScript is downloaded to the
browser, and then compiled into byte code. The resulting byte code (to
my knowledge), is smaller than the original script.
Well, not necessarily. If you're looking for a Javascript compiler,
Rhino has one (
http://www.mozilla.org/rhino/jsc.html), but has it was
said in this thread, browsers implements their own interpretation of
the language (
http://en.wikipedia.org/wiki/JavaScript)
Unlike Perl or PHP, Javascript files aren't kept in a cache since it
wasn't originally made to support large, extensive, data
manipulations ; it's a scripting language to enforce server scripting,
a mean to control the portion of HTML loaded onto the client's
computer (I'm strictly talking Web scripting here). To extend the
limitations, IE added ActiveX to it's list of features (an ugly
feature if you ask me... security and standard-wise)
Should there be a Web standard that allows us to compress code into
bytecode, and then send the byte code directly to the browser?
I did think about having a pre-compiled scripting standard for
browsers, but the fact is that as computer evolves, there is less and
less need to do so, and interpreted or executed, the speed difference
tends to be more and more negligeable. Browser scripting will always
be, at a level or another, interpreted. There is a long way before
achieving performances like compiled C++ for the Web, because 1) C++
is OS and hardware specific, 2) every browsers implements their own
memory allocations for DOM ressources, 3) for security reasons, it is
the browser's responsibility to handle policies, so it has to
interpret the script whatsoever.
As for code size, there are alternatives : code obfuscators, and code
compressor (like here :
http://javascriptcompressor.com/)
Perhaps there is a flaw, in the sense that bytecode is different from
browser to browser, but isn't that what standards are all about?
As a final note, I would hate having to recompile my Javascript files
all the time... mostly because many of my scripts depends on other
scripts, and HTML files.... Since there will always be things like
<div onclick="foot();"></div> (interpreted scripts) I don't see why
adding new "embrace and expands from Microsoft through new ways of
handling data" will help in restoring compliancies (*grin*) KISS
I'd be interested in hearing the opinions of others on this subject.
Cheers !
- Yanick