Is it possible to have various javascript files for debugging and production in a web application?

I would like to have different versions of javascript .js files in an ASP.NET WebForms application (VS 2008):

  • full version, comments, etc.
  • shortened version for production

Is there a way to automatically get the full version when debugging and the smaller version when the application is deployed for production? I do not mind if the answer is hacked.

Is this possible in VS 2010?

+3
source share
2 answers

I like to use the SquishIt library.

CSS JavaScript .

EDIT: . , , .aspx MVC. :

  • HTML

, #debug , , .

CSS javascript minfication.

.

+3

, , ", ."

, DEBUG. , .

, - :

<% #if DEBUG %>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js"></script>
<% #else %>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<% #endif %>

, Literal .

<asp:Literal runat="server" ID="txtScripts" EnableViewState="false" />

protected void Page_Load(object sender, EventArgs e)
    {
#if DEBUG
        txtScripts.Text = "<script type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js\"></script>";
#else
        txtScripts.Text = "<script type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js\"></script>";
#endif
    }

- javascript - DEBUG .

MS Ajax MInified http://www.asp.net/ajaxlibrary/AjaxMinDocumentation.ashx javascript, .

Minifier MyMin = new Minifier();
CodeSettings cs = new CodeSettings();
#if DEBUG
    cs.MinifyCode = false;
    cs.OutputMode = OutputMode.MultipleLines;
    cs.PreserveFunctionNames = true;
    cs.RemoveFunctionExpressionNames = false;
    cs.RemoveUnneededCode = false;
    cs.StripDebugStatements = false;
#else                   
    cs.MinifyCode = true;
    cs.OutputMode = OutputMode.SingleLine;              
#endif
Write(MyMin.MinifyJavaScript(AllMyJavascript, cs))
+6

All Articles