I'm a little confused. I have my _layout.cshtml page below and it has a bunch of bundles containing .css and .js files. When I first load the site it runs through each file in the bundles. Fine, OK, great! But then on each new view, each line of code from every file gets run through again! (ex. jQuery, bootstrap, etc) I set break points to test this and they were all hit every time I loaded a new view.
I thought the whole purpose was the browser would be to cache these files so they wouldn't load each time a new view gets called? Am I missing some understanding here? Did I not set up the layout correctly? Are they not being loaded but the code is being run through (that's why all my break points are being hit) with each new view?
Is there a way to set it up so this doesn't happen and all the files are loaded once when my clients visit my home page? I don't understand why each .js file (ex. bootstrap) is loaded on every view that gets loaded!!
Here is my layout page
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<title>Yogabandy - @ViewBag.Title</title>
@Styles.Render("~/Content/yogabandy-base/css")
@RenderSection("content", required: false)
@Scripts.Render("~/bundles/modernizr")
</head>
<body>
@Html.Partial("_Navbar")
@RenderBody()
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDUWFuy0zfuKe4uig_koh3O6SRDaf40gA4&libraries=places" async defer></script>
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@Scripts.Render("~/bundles/jqueryval")
@Scripts.Render("~/bundles/yogabandy-base")
@RenderSection("scripts", required: false)
</body>
</html>
If you are not using
SPAorPartial view/page rendering, when you navigate from one view to another view a complete post back will happen and new content will be loaded to the DOM, in that case all the resources will be requested again by the page to the server. If the content likeJS/Images/CSSis already cached, in that case content will not be loaded from server but from the cache, but complete JavaScript will execute again.If you don’t want this to happen, go for partial page rendering or implement
SPA.You can read more about SPA here https://www.asp.net/single-page-application AND MSDN