简体   繁体   中英

How to prevent keywords from getting obfuscated when using Google Closure Compiler?

I am trying to obfuscate javascript files (Around 50) using the Google Closure compiler. the files all depend on one another.

In simple mode, it obfuscates only local variables.

In advanced mode, it obfuscates all the variables and functions including certain keywords that I do not want to obfuscate(args, readline, atEnd).

How can I obfuscate some of the variables but not others? Specifically: I don't want the keywords to get obfuscated.

There is a pretty significant difference between ADVANCED and SIMPLE modes. Advanced optimizations are only appropriate for code bases which are designed not to violate any of the compiler restrictions . Before continuing, you might read Which Compilation Level is Right for Me?

The answers to your question are externs and exports:

  • Externs prevent the compiler from renaming symbols in external libraries
  • Exports preserve symbols in your code for use elsewhere

I don't have experience with Google Closure Compiler, but to obfuscate my projects I use Jscrambler. It lets you prevent keywords from being obfuscated using a blacklist that they refer as "Rename Exclude List" . I use this feature sometimes when I have delicate function names that otherwise would break my code if they had got obfuscated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM