Witcraft home page

July 21, 2010

How to use hosted versions of popular javascript libraries only after deployment in asp.net mvc

There is good website performance practice to use hosted version of popular javascript libraries such as jquery after deployment. However, while running application on local developer machine you’d better to use local version instead.

To solve this problem in ASP.NET MVC you could use IsLocal property of request class.

<% if (Request.IsLocal) {%>
<script src="/Scripts/jquery.js" type="text/javascript"></script>
<%} else {%>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<%}%>

This trick allows you to inject hosted versions of javascript libraries on deployment server and local version on localhost.

-

Leave Comment