When I develop application, I want to use jquery-1.3.2.js, and when I deploy it, I want to use jquery-1.3.2.min.js?
What is the best way to switch between two without manually commenting and uncommenting one.
Thanks.
When I develop application, I want to use jquery-1.3.2.js, and when I deploy it, I want to use jquery-1.3.2.min.js?
What is the best way to switch between two without manually commenting and uncommenting one.
Thanks.
Name both files jquery.js for example, and put in some folder (libs) When you deply, don't deploy lib folder.
I'm sure someone can translate this answer into asp.net: I do a conditional based on my APPLICATION_ENVIRONMENT
defined in my projects. Not sure if there is a similar thing in asp.net, but if you are on a production server, you can serve .min - and on a development/testing machine you can serve the full library.
If you are programmatically adding the declaration, then the best way is to use the
#if DEBUG
Compiler directive. In the DEBUG area use your fully expanded library, and in the non-DEBUG (when you compile in Release mode for publication) put the .min version. Then you only need to worry about making sure you compile Release when you go live.
Alternatively, have seperate .config files for your different release environments and specifiy your javascript includes in there.
If you are using django, you can use django-compress to handle this automatically.
I have a HtmlHelper extension method to load my JavaScript files. It looks something like this...
public static string JavascriptTag(this HtmlHelper html, string javascriptName)
{
var format = "<script src=\"/Content/Scripts/{0}.js\" type=\"text/javascript\"></script>\r\n";
#if (!DEBUG)
javascriptName += ".min";
#endif
return string.Format(format, javascriptName);
}
Which is called very simply like:
<%= Html.JavascriptTag("jquery-1.3.2") %>
<%= Html.JavascriptTag("general") %>
I can use this convention because I also have a build task that takes all JS files inside my content/scripts directory, minifies them and then inserts .min into the filename.
If you don't have that luxury, you could use a variation like so:
public static string JavascriptTag(this HtmlHelper html, string devFileName, string liveFileName)
{
var format = "<script src=\"{0}\" type=\"text/javascript\"></script>\r\n";
var fileNameToUse = devFileName;
#if (!DEBUG)
fileNameToUse = liveFileName;
#endif
return string.Format(format, fileNameToUse );
}
Which could then be called like:
<%= Html.JavascriptTag("/Content/Scripts/jquery-1.3.2.js", "/Content/Scripts/jquery-1.3.2.min.js") %>
<%= Html.JavascriptTag("/Content/Scripts/general.js", "/Content/Scripts/general.min.js") %>
HTHs,
Charles