0

I am working on a angularjs module in which we are trying to avoid a particular piece of logic in the view source on the browser. I have just given the skeleton code where the logic written inside script tags should not be shown in the page source of the browser.

<html ng-app="myApp">
     <head>
         <script>
            if(something){
            do something...
            }
         <script>
     </head>
     <body></body>
</html>

Is there any way in angularjs or javascript such that the logic written inside script is not visible in view page source on browser?.

Mistalis
  • 17,793
  • 13
  • 73
  • 97

3 Answers3

0

This is not possible as the code needs to be executed by the browser, thus transferred to the client. Anyone can read/copy your code.

The most you can do is to use uglify or similar tool to minify your code. This will have to advantages for you. First, your code will be hard to read for others who might want to exploit your application. But keep in mind, it is still not impossible to understand your code even when minified - it just takes more time. And second, your scripts will become smaller thus making your page load slightly faster.

Vladimir Zdenek
  • 2,270
  • 1
  • 18
  • 23
0

You can't hide code to your client. It is executed in the client browser.

The best thing you can do here is to minify your code. It will make it unreadable without parsing it. Also, the code will be smaller, and will be loaded by the browser faster.

As a side note, luckily all the code is visible: imagine if malicious code could be executed without you know it.

Mistalis
  • 17,793
  • 13
  • 73
  • 97
0

One more solution is make it look a bit complex so the user trying to read it does not understand it(in case you are not interested in making a minfied version)

  • Store all the Variables required in a separate file and access them form that file.
  • Even your base URL should be stored as global variable.

These are some options which you can use but making a minfied code is best practice.

Rohan Kawade
  • 453
  • 5
  • 18