Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi, i noticed that when i view my html pagesource i see my javascript references and when i click on them, i could see all my javascript code. please how to i restrict users from viewing my javascript code when they click on the link in the page source. i'm coding with mvc5.

What I have tried:

C#
public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.IgnoreRoute("/Scripts/{*path}");//this is the path to all my javascript files
            routes.IgnoreRoute("{resource}.config");
            routes.IgnoreRoute("{resource}.cs");
            routes.IgnoreRoute("{*allfiles}", new { allfiles = @".*\.(css|js|gif|jpg|png|doc|docx)" });

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }
    }

i did that but it didn't work
Posted
Updated 29-Apr-16 3:33am

1 solution

You don't.

In order for the browser to execute your script, it has to be able to download your script. If you prevent the user from downloading your script, then your prevent the browser from executing your script, and you break your site.

Any operation which needs to be kept secret should be done in server-side code. Anything you do in HTML, CSS or Javascript will be visible to everyone.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900