PDA

View Full Version : Hiding JavaScript source from the user.


MagSafe
2008-06-27, 16:30
Hey folks,

So I'm about to start working on a web app. I work with HTML/JS/XML/server side code daily as my job so I've been dying to try out an idea of my own I've had for a while now.

I'm going to be creating my own JS framework for it, instead of using something like SproutCore as I'd like full control over the whole thing, and also so I can improve my knowledge of things like that as well.

Many people will probably argue this (from what I've read on other forums anyway); but at the end of the day I'd like to hide my JS from the user. As 'web apps' start becoming more & more like actual software ran on the operating system, you don't see app's like Photoshop, Logic, etc making their code openly available.

I'd like to do something like...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>untitled</title>
</head>

<body>
Loading...
</body>
</html>

...but to not include any script tags or an onLoad event.

Even if this can't be done, I'd like to know of people's recommendations for ways to make it as inaccessible as possible.

Cheers for any advice :)

Steve.

Brad
2008-06-27, 16:44
I'm pretty sure what you're asking isn't possible with current browser technology and web standards. :)

colivigan
2008-06-27, 17:16
What Brad said.

At best, you can load the JS by using <script src=url> tags, which at least won't show the code in a view source. But anyone could still point their browser at the URL in the src attribute and get the code.

There are also tools for rendering the code pretty unreadable, Google "obfuscate javascript" for a sampling.

Brad
2008-06-27, 17:30
You can also gzip your code, but that also only obfuscates it from casual users.

MagSafe
2008-06-27, 18:35
There are also tools for rendering the code pretty unreadable, Google "obfuscate javascript" for a sampling.

This sounds like what I'm after, thanks! :) Even though it still makes the code accessible to those who really want to get there hands on it, it at least makes it look more professional by removing all the comments, formatting etc that's used.

Could anyone recommend an (obviously Mac compatible!) app for doing this? After a quick search there doesn't seem to one that stands out as being the best, or at least most popular among web developers.

Brad
2008-06-27, 19:10
I must warn against using JavaScript obfuscators because some of them change the way the code is executed, potentially introducing bugs or unintended side-effects. If you use one, be sure to test heavily afterwards in all browsers you wish to support.

synotic
2008-07-03, 02:58
This sounds like what I'm after, thanks! :) Even though it still makes the code accessible to those who really want to get there hands on it, it at least makes it look more professional by removing all the comments, formatting etc that's used.In what sense does it seem more professional? If anything, in the current web development culture it seems to me to be very unprofessional to hide your code.

With Apple opening up the guts of its MobileMe service with the release of SproutCore, and its reliance on open frameworks like Scriptaculous and Prototype for its consumer-facing websites, even real software companies are making their code openly available.

Why do you want to do this again? :)