Guarding Your Internet Site
When it comes to a public website, achieving total code invisibility is simply not feasible. While you can attempt to obfuscate the code, ultimately the browser needs access to it in order to execute, allowing users to uncover the code if desired.
You could potentially delve into more intricate forms of obfuscation, crossing into DRM territory. However, this still wouldn't prevent determined individuals from obtaining and potentially deciphering the (obfuscated) script.
Because JavaScript runs on your users' machines, there must be an element of trust involved. Going beyond basic minification with code obfuscation may raise suspicions, hinting that the hidden functionality could harm users or their devices.
As mentioned by others, truly secretive code should be strictly server-side to ensure only the results are delivered to clients.
Restricted Environment
The dynamics shift in an intranet setting where the IT department boasts control over both the intranet server and client computers. Here, they have the capability to disable browser inspection features and prevent downloading or scraping of scripts from browser caches.
This setup essentially mandates computers configured solely as web kiosks - stripped of the ability to run unauthorized programs. Authentication mechanisms would need to be tight to safeguard against outsiders plugging in their own devices to access JavaScript code.