Best place for javascript in Asp.net MVC application that heavily uses partial views

What is the best place for javascript, typical for partial viewing? For example, if I have a partial view (loaded via an ajax call) with some divs, and I want to turn these divs into harmonics, it would be better to put $ ("# section"). Accordion () in script tags inside a partial view or in a .js file in a function that extracts that partial view and inserts it into the DOM?

Obviously, the general methods that I will store in the .js file, however, I talk more about the fact that javascript is very specific for partial presentation.

Most of the things I find on the web seem to say to put all javascript in a separate .js, but nothing addresses the idea of ​​partial views.

+3
source share
1 answer

You can think of partial views as plain html on your web page if that helps. The browser does not distinguish between html in a partial view and the rest of the html surrounding it.

According to this logic, the best place to place Javascript (including links to external scripts) on a web page (regardless of whether it contains html that is part of a partial view or not) is in a canonical location at the bottom of the page, although there are exceptions.

, Javascript-, html script, - , script. .

+3

Source: https://habr.com/ru/post/1742561/


All Articles