Ben Griswold
Ben Griswold

Reputation: 18361

Why Might Masterpage Javascript File References be Wrapped in a PlaceHolder Control?

While reviewing the demo project for the xVal, a validation framework for ASP.NET MVC, I noticed Masterpage javascript references were wrapped in an PlaceHolder control:

<asp:PlaceHolder runat="server">
    <script type="text/javascript" src="<%= Url.Content("~/scripts/jquery-1.3.2.min.js") %>"></script>
    <script type="text/javascript" src="<%= Url.Content("~/scripts/jquery.validate.js") %>"></script>
    <script type="text/javascript" src="<%= Url.Content("~/scripts/xVal.jquery.validate.js") %>"></script>
</asp:PlaceHolder>

I'm not sure I see the benefit of the PlaceHolder control over merely referencing the files directly:

<script type="text/javascript" src="/scripts/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="/scripts/jquery.validate.js"></script>
<script type="text/javascript" src="/scripts/xVal.jquery.validate.js"></script>

What am I missing?

Upvotes: 0

Views: 249

Answers (1)

Blair Scott
Blair Scott

Reputation: 1885

Sometimes you only need the JS files on a single/few page(s). When that is the case it helps to only load them on the pages you need them, thus the placeholder. I've actually found myself having to do this quite a bit recently, and it definitely does help, at least in my case. If nothing else, it keeps things a little less cluttered.

Upvotes: 1

Related Questions