Include JavaScript file in partial views

后端 未结 9 1508
别跟我提以往
别跟我提以往 2020-12-02 06:13

I am wondering what the best practice is for including javascript files inside partial views. Once rendered this will end up as a js include tag in the middle of my page\'s

9条回答
  •  温柔的废话
    2020-12-02 06:47

    The preferred approach is to put scripts at the bottom, however, if you can't avoid that then it's reasonable to put them in the middle.

    Browsers usually load the various page elements in parallel, however, while the browser is downloading the Javascript file, it won't download any other page elements in parallel until the Javascript is done downloading. This means that your images and what not will have to wait so it's generally considered better to move scripts at the bottom but if your script is small then I wouldn't worry about it.

提交回复
热议问题