encrypt javascript

Discussion in 'JavaScript' started by srdva59, Jul 24, 2009.

  1. #1
    hi,
    i have this code for example in my html or in a .js file
    and i want know if there is some way to encrypt or dificult the reading
    by humans

    ex:

    var a=1
    if x==1 [ etc

    thanks for your help
    :)
     
    srdva59, Jul 24, 2009 IP
  2. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Well there's no real way to actually 'encrypt' the javascript, but you can obfusicate it (making it difficult to read/edit).

    One of the most popular way to do it is to use a packer.
    http://dean.edwards.name/packer/ The dean edwards packer was one of the first ones to become heavily popularized.

    But like with some obfuscation methods, the same generator can often times decode them again.

    Here are some that may be better suited.
    Dojo ShrinkSafe : http://shrinksafe.dojotoolkit.org/
    YUI Compressor : http://developer.yahoo.com/yui/compressor/
    JSMin (Popular with Jquery) : http://www.crockford.com/javascript/jsmin.html

    Personally I prefer JSMin, but not everyone likes the command line approach.

    Since they don't provide true security so to speak (Even though they thwart off most people who don't have the knowledge to reverse it), they are handy for reducing the file size for a quicker loading site.
     
    kblessinggr, Jul 24, 2009 IP