SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Location
    Molde, Norway
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Advanced minify of javascript objects

    I have developed an application in javascript, and my company wants to minify and obfuscate the code before we publish it on the webpage. The application is built as one javascript object with attributes and functions inside. Example, so that you can understand the structure:
    Code:
    function MyApp(){ 
      /** @private */
      this.effect=0.2;
    
      this.var1="test";
      this.var2=34;
    }
    
    /**
     * 
     */
    MyApp.prototype.initialize = function() {
      // code here
    }
    
    /**
     * @private
     */
    MyApp.prototype.print = function() {
      // code for private function here
    }
    Some of the functions are private, and so are some of the objects variables/attributes as well. I use JSDoc to mark them private, and NetBeans (the IDE I use) will mark them and treat them as private. The problem is that minifyers and iglyfiers will not abfuscate the private functions and variables/attributes. Only the local variables inside the functions are obfuscated.

    Does anyone have a tip?

    I hope to use yui compressor as my main tool for minifying.
    Software developer at ADCom Data
    My blog for dumping information

  2. #2
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,606
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    There's a whole slew of webapps that will minify javascript. Some--but not all--include obfuscation features.

    http://www.google.com/search?q=javas...ascript+minify
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Location
    Molde, Norway
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Force Flow View Post
    There's a whole slew of webapps that will minify javascript. Some--but not all--include obfuscation features.
    Short version of my question is: What application is able to obfuscate/minify the function names of private functions in an object? Do I have to change my code for that to be possible?

    I have been googeling this without finding the answer.
    Software developer at ADCom Data
    My blog for dumping information

  4. #4
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,258
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    Google's Closure Compiler using advanced compilation is probably your best bet. Though, yes, you will need to change you code.
    "First make it work. Then make it better."

  5. #5
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,606
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    I've seen one tool that can obfuscate code which is inside functions and leave the function names and outside variables alone, but I can't remember what it was called. I just did a search and happened to stumble across it.
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •