views:

1009

answers:

6

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.

+2  A: 

Name both files jquery.js for example, and put in some folder (libs) When you deply, don't deploy lib folder.

Sorantis
Or just use a symbolic link.
Daniel Straight
Does Windows have symlinks?
middus
+2  A: 

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.

gnarf
+1  A: 

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.

MSDN link to compiler directives.

Evildonald
This seems to be that similar thing I am talking about in my answer.
gnarf
Seems to be. Except I suggest 2 alternatives and I also I included examples and link, which are generally more helpful. Also this is tagged asp.net-mvc, so my answer was .net specific.So really, not that similar.
Evildonald
A: 

You can name script as jquery.js. And add two other js files. First will be named as jquery.js.debug, other onw jquery.js.release. And when compiling application use appropriate js file.

I'm using it to change web.config files. Additional information can be founded here.

Sly
A: 

If you are using django, you can use django-compress to handle this automatically.

DataGreed
+3  A: 

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

Charlino