2

Heh, that's something that many plugin authors do without needing help, isn't it? :) Here's the rub -- I'm coding a jQuery plugin which I have the intent to sell. I want to provide a live demo of it; of course, I don't want anyone just using the demo code.

I know it's dumb, and it certainly doesn't bring any good karma, but what are some naughty things I can do in the demo script that would make life reasonably difficult for anyone trying to use it? Setting undefined = true comes to mind, as well as overriding jQuery methods. Any suggestions beyond that?

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
avramov
  • 2,119
  • 2
  • 18
  • 41
  • 9
    If you show it in demo, anyone then can use it according to your demo. The best thing is to relax. Good boys will buy your script. Bad boys will use it for free. And nothing you can do with that! ;) – antyrat May 11 '12 at 15:21
  • make a flash version of what it does and let people play with that. Private viewing only, at your office, no touching permitted – musefan May 11 '12 at 15:22
  • possible duplicate of [How can I obfuscate JavaScript?](http://stackoverflow.com/questions/194397/how-can-i-obfuscate-javascript) – Sparky May 11 '12 at 15:28
  • 3
    JavaScript is 100% open-source. – zzzzBov May 11 '12 at 15:28
  • You certainly don't want to set `undefined = true` if you expect people to use the plugin – Nevir May 11 '12 at 15:28
  • @Nevir: I think he meant just in the demo version of it. – T.J. Crowder May 11 '12 at 15:29
  • @Sparky672: Not *quite* the same as that question. This is more targeted (and probably more achievable). – T.J. Crowder May 11 '12 at 15:31
  • You want to make money from your code but expect us to to write stuff for free? – symcbean Jul 16 '12 at 12:42
  • @symcbean - I humbly ask to be provided with ''advice''. It is my understanding that many users here earn their living by coding, so I cannot understand your sentiment. – avramov Jul 16 '12 at 13:04

8 Answers8

14

I like Diodeus's idea of a video (or a screencast, etc.).

But if you absolutely, positively want an interactive demo, take jQuery, your plugin, and your demo code, put all three together, and throw the Closure Compiler at it (with advanced optimizations if you can get that to work with jQuery; with simple optimizations otherwise). The Closure Compiler is a lot more than just a minifier; it actually re-writes your code, inlining functions (even in simple mode), changing identifier names, etc. If all the code is compiled together, you don't have to tell it to "export" any symbols, it can have a renaming, inlining frenzy. :-) It will conflate the three parts (jQuery, plug-in, and demo) such that it'll be far more work than it's worth to unravel them.

Community
  • 1
  • 1
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
10

The JavaScript environment, by its very nature, is insecure. Other than minifying the code, there's nothing you can really do. If the browser can see it, the user can see it. It's the same argument of trying to prevent people from stealing your images.

If you want to make a demo, make a video of it.

Diodeus - James MacFarlane
  • 112,730
  • 33
  • 157
  • 176
3

Don't make your deno code a jQuery plugin: instead, make it a plugin for a library that is functionally equivalent to jQuery.

Basically, take a copy of jQuery and rename all of the functions in it (and/or swap around the order of function arguments). Then make a demo copy of your plugin that is modified to use the new, messed-up copy of jQuery.

Alternatively (or additionally), minify it and have it torch/delete/ruin any component of jQuery that it doesn't need. Anyone who wants to use your minfied code will find their jQuery object has been substantially altered.

There are fairly simple workarounds to all of these defenses, but it might keep away anyone not sufficiently dedicated to understanding what's going wrong. In the end, you may find it's simply not worth the effort and just trust that honest customers will make development worth your while.

apsillers
  • 112,806
  • 17
  • 235
  • 239
  • -1 - so You are suggesting people have to load same content twice? Bad idea. – epascarello May 11 '12 at 16:23
  • 2
    @epascarello: I'm suggesting that the OP use a modified version of jQuery *instead of* ordinary jQuery on the demo page. What are vistors loading twice when they visit the demo page? – apsillers May 11 '12 at 16:50
2

Add a check which will only pass on your own host. Then minify the code to obscure the workings.

trapper
  • 11,716
  • 7
  • 38
  • 82
  • 2
    this wont help... the easiest thing to spot in the minified code will be the string with the host name that needs to be changed – Robert Levy May 11 '12 at 15:24
  • Good one! @RobertLevy -- not if the string is base62/64 encoded, and so is the entire code, as provided by [Packer](http://dean.edwards.name/packer/) – avramov May 11 '12 at 15:25
  • 2
    I would do something not quite so obvious anyway - check the 3rd letter is an 'a' and the 5th letter is a 'b' should do the trick ;) – trapper May 11 '12 at 15:27
2

Any many posts have suggested, most JavaScript can can ripped off without too much hassle, although it is possible to make it difficult for people. I would recommend using a good JavaScript Obfuscator; I found this one just now, and it seems to make it pretty unread-able to even the trained eye.

Before:

var somethingToSay = "hello world";
function saySomething(phrase)
{
    alert(phrase);
}
sayHello(somethingToSay);

After:

eval(function(p,a,c,k,e,d){e=function(c){return c};if(!''.replace(/^/,String)){while(c--){d[c]=k[c]||c}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('2 0="3 4";8 5(1){7(1)}6(0);',9,9,'somethingToSay|phrase|var|hello|world|saySomething|sayHello|alert|function'.split('|'),0,{}))

It's worth noting, that with any obfuscation, there might be a slight performance hit, but it's the price paid for "securing" your work.

Richard
  • 8,110
  • 3
  • 36
  • 59
1

You can minify the code to make it harder to read.

Sachin Kainth
  • 45,256
  • 81
  • 201
  • 304
1

Publish your 'demo' in the form of a screen recording rather than live code.

Robert Levy
  • 28,747
  • 6
  • 62
  • 94
0

If it's out there, it can get ripped off. You can minify, obscure, do weird things to the source code like splitting it over a bunch of JS files, but it can still be ripped off. If you really want a demo, have you considered recording a video demo?

Ashley Strout
  • 6,107
  • 5
  • 25
  • 45