Frontend Code Security

Frontend Code Security

Mar 12, 2021 · 1 min read · 81 Words · -Views -Comments

Frontend resources ship to browsers/clients. How do we best protect JS and other assets to reduce risk of code theft in commercial projects? The goal is to raise the barrier and increase the cost of stealing.

Practical measures I’ve used:

  1. Build in production mode; strip debug info.

  2. Minify CSS/HTML/JS.

  3. Add hash to CSS class names.

  4. Minify and mangle JS identifiers (e.g., via terser).

    • 比如利用terser

  5. Consider code obfuscation where appropriate.

Alan H
Authors
Developer, Tech Enthusiast, Open Source Advocate