Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

switch between jquery-1.3.2.js and jquery-1.3.2.min.js

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.

like image 294
J.W. Avatar asked Oct 06 '09 01:10

J.W.


People also ask

What is the difference between jQuery and jQuery min?

min. js is a compressed version of jquery. js (whitespaces and comments stripped out, shorter variable names, ...) in order to preserve bandwidth. In terms of functionality they are absolutely the same.

Why we use jQuery min JS?

The sole benefit of minified jQuery file is allowing a client to download fewer bytes , enabling the page to load faster, use less battery, use less of a mobile data plan, etc. The jQuery-x.x.x-min. js file will be more than 50% less than the normal js file. Reduction in the file size makes the web page faster .


2 Answers

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") %>

An added bonus of the approach above is that you can use a CDN for libraries, e.g.

<%= Html.JavascriptTag("/Content/Scripts/jquery-1.8.2.js", "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js") %>
like image 105
Charlino Avatar answered Sep 20 '22 17:09

Charlino


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

like image 38
Sorantis Avatar answered Sep 22 '22 17:09

Sorantis