Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

Can any suggest we best practice to save JS code Area wise in MVC.
currently I found in many application JS code is writtern in .cshml

E.g.
E:.
├───Controllers
├───Models
└───Views
    ├───Listserv
    └───Shared


All JS code is find in .cshtml

Can I crate dedicated JS Area wise? Any best practice suggestion here?
Thanks in advance.
Regards,
Sanjay

What I have tried:

No nothing so far. I am just look at various projects.
Posted
Comments
[no name] 18-Jan-18 7:55am    
Yes you can go with dedicated js code area wise and can place them in views shared folder
David_Wimbley 18-Jan-18 14:02pm    
When you create a new project doesn't it auto create a Scripts folder and you just put your JS in there? If thats not what you want you are free to put it anywhere you want and just reference it in your BundleConfig.cs file.
Sanjay Sharma 19-Jan-18 0:23am    
If I have account.js & Profile.js won't you think adding both at BundleConfig load the file when actually I need only one at a time?
David_Wimbley 19-Jan-18 10:46am    
Create a bundle per page so that you only have relevant JS for each page. I'm of the opinion that it probably doesn't really matter as most of the stuff i work on...trying to save a few milliseconds of download speed isn't crucial for me so i just use BundleConfig.cs

1 solution

@
David_Wimbley

Adding that in
BundleConfig.cs
don't you think that will added when those script are actually not required?

Assume I have "Account" & "Profile" functionality js for both is different.
If I add then in
BundleConfig
won't both js get loaded where I might not need both at same time.
 
Share this answer
 
Comments
Richard Deeming 19-Jan-18 11:20am    
If you want to reply to a comment, click the "Reply" button next to the comment.

DO NOT post your reply as a "solution".

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