We're looking to enhance the functionality of a view page with some Ajax functions. This means that when a user clicks on a delete or insert button, an Action will be triggered to carry out a CRUD operation in the background, followed by refreshing the items list once the task is completed.
In many instances, JavaScript code is typically embedded within the <script>
tag directly on the view page. However, considering that multiple functions may be required for a single view (such as collecting form data, validating it, and then making an AJAX call), we are contemplating moving all these scripts into a separate .js file.
Regarding best practices, should we store these .js files in the same folder as their respective Views? Or would it be better to place them all in a centralized 'Script' folder and reference from there?
Furthermore, should each individual view have its own separate .js file, or would it be more efficient to combine all scripts for different views into a larger file?
Additionally, just like how C# code can be grouped using #region for organization, is there a similar feature in JavaScript to help manage lengthy scripts effectively?
We appreciate any advice you can provide on this matter. Thank you.