In working with a test project for ASP.NET Web API, I noticed an interesting script reference in the _Layout.cshtml.
<script src="System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl(“~/Scripts/js”)”> </script>
Because this url is apparently pointing to the directory and the file extension, I wanted to know if indeed the scripts were being pre-loaded from this one script call. So I ran the application and clicked on “View Source” in the browser where I found the following source code:
I’ve removed some of the markup for brevity, but left the main sections to illustrate my point. As you can see in the markup there are two DOCTYPE elements, two <head> sections as well as two <body> sections. In essence, we have a web page wrapped in a web page and interestingly enough, the browser rendered it.
So I took a look at the template file as well as the index view for the home controller and indeed found that both pages contained full page declarations. As a result, the RenderBody() call from _Layout.cshtml caused all of the content in Views/Home/Index.cshtml to render including the doctype, head, and body tags.
I presume that this would not present an issue unless you attempt to traverse the DOM using jQuery or some other script library. This is where you may experience some unexpected results. In any case, if you are at all familiar with ASP.NET MVC then you are already familiar with how to clean this up, in fact, the instructions on the page itself are to replace the contents with your own. My recommendation is simply to ensure that you remove the repeating page declarations in the Index.cshtml page as well.
On another note, I didn’t actually resolve my question by going through this which is, are the scripts being pre-loaded. The Scripts folder does contain a _references.js file which we know the “_<filename>” convention in ASP.NET MVC generally means a special/reserved file. The file contains a few commented lines referencing other script files contained in the directory. I presume that if you uncomment these lines, then the files will be loaded together resulting in one HTTP request instead of one for each file.