Code Optimizers Can Make View Source Useless

Image: Wikipedia/CC

HTML, CSS and JavaScript have always been visible to the interested end user. Whether through the good old view source option in your browser, or something a bit more sophisticated — like developer favorite Firebug — the code has always been there to learn from.

It’s part of what makes the open web open. But when it comes to JavaScript, it’s possible that openness may soon be a thing of the past.

What’s different from some tools in other languages (like ActionScript obsfucation tools) is that Closure and others of its ilk aren’t primarily designed to obfuscate, they’re simply optimizing code, making it smaller and faster. As Russell writes, “the Closure Compiler can deliver code that’s much, much smaller than I can wring out by hand and that performs better to boot.”

In other words Closure creates better, faster JavaScript.

However, there’s a trade off that most of us generally ignore — the code generated by such tools is useless from the perspective of curious users trying to learn JavaScript by viewing your source code.

As Russell writes in a followup comment, “poll any average group of web developers and they’ll tell you straight-up that that’s how they learned… not be stealing, but by dissecting and inspecting and tweaking and then re-implementing a technique in a new and unique situation.”

Webmonkey’s own seminal JavaScript tutorial advises: “the best way to learn JavaScript is to look at scripts other people have written. JavaScript, just like HTML, can be viewed by selecting View Source on your browser. Do it frequently!”

Tools like Closure make the source you view of little use. True there are some “de-obfuscation” tools out there — like jsbeautifier.org — but none of them work with tools as sophisticated as Closure.

Now curious newbies trying to teach themselves JavaScript may not be top of your list of concerns when writing code for your website, but Russell is right when he suggests that these “second-order beneficial effects,” that is, the ability to view source and learn from it, are part of what has made the web a success.

The danger is that in taking away the usefulness of view source we’re creating a much less democratic environment for those trying to learn HTML, CSS and JavaScript from tomorrow’s web. And as Russell writes, that’s not “a vision of the web that holds my interest.”

So what’s the answer? Well, there isn’t one really. Some ideas floated by Russell and commenters on his post include letting browsers do the Closure-style byte code compiling before the script is rendered, building better de-obfuscation tools or simply serving up uncompiled versions of the same JavaScript for interested users.

Here’s The Thing With Ad Blockers

We get it: Ads aren’t what you’re here for. But ads help us keep the lights on. So, add us to your ad blocker’s whitelist or pay $1 per week for an ad-free version of WIRED. Either way, you are supporting our journalism. We’d really appreciate it.