3 Replies Latest reply on Oct 26, 2012 6:52 AM by justin_at_adobe

    Minification/Obfuscation

    Bayani Portier Level 1

      We have a package with a stack of javascript containing ridiculously long variable names. We can't instruct the developers to rename their variables this late in the piece, so I'm hoping that we could leverage obfuscation, rather than just minification.

       

      Incidently, minification can be turned on by navigating to {ServerURL}/system/console/configMgr, going to the Day CQ HTML Library Manager, and clicking on the Minify checkbox.

       

      This would work well if it were whitespaces and comments causing the issue, but what we really need to get the file size down is to be able to compress by obfuscating the variable names.

       

      Is there a config that I've missed somewhere, or does anyone know of a third party tool that we could use?

        • 1. Re: Minification/Obfuscation
          justin_at_adobe Adobe Employee

          The minification process will do some obsfucation, but it is limited based on scope. For example, a line like:

           

          window.somereallylongvariablename = "foo"

           

          wouldn't be obsfucated because "somereallylongvariablename" still needs to be set on the window object.

           

          This, however, would be:

           

          function foo(somereallylongvariablename) {

              console.log(somereallylongvariablename);

          }

           

          probably to

           

          function foo(A) { console.log(A); }

          1 person found this helpful
          • 2. Re: Minification/Obfuscation
            Bayani Portier Level 1

            Hi Justin,

             

            Thanks, that makes a lot of sense.

             

            So I would assume then it is somewhat of a fools errand to obfuscate the entire JS project on this level due to the risk of breaking something, or should I continue to pursue a full obfuscator?

            • 3. Re: Minification/Obfuscation
              justin_at_adobe Adobe Employee

              I don't know your project constraints so I can't say whether or not this is a good use of time.

               

              What I can say (with the caveat that I haven't see the JavaScript code in question) that my experience is that the YUI Compressor (which CQ uses internally) does a good job minifying good JavaScript and a bad job minifying bad JavaScript. So if the minification isn't minifying enough, then I'd try refactoring the JavaScript before trying to replace the minification process.