Saturday, May 11, 2024
Homepage · c#
 Popular · Latest · Hot · Upcoming
170
rated 0 times [  175] [ 5]  / answers: 1 / hits: 25016  / 15 Years ago, wed, may 20, 2009, 12:00:00

As an extension to this question here Linking JavaScript Libraries in User Controls I was after some examples of how people are concatenating and minifying JavaScript on the fly OR at build time. I would also like to see how it then works into your master pages.



I don't mind page specific files being minified and linked inidividually as they currently are (see below) but all the JavaScript files on the main master page (I have about 5 or 6) I would like concatenated and minified.



Bonus points for anyone who also incorporates CSS concatenation and minification! :-)



Current master page with the common JavaScript files that I would like concatenated and minified:



<%@ Master Language=C# Inherits=System.Web.Mvc.ViewMasterPage %>
<head runat=server>
... BLAH ...
<asp:ContentPlaceHolder ID=AdditionalHead runat=server />
... BLAH ...
<%= Html.CSSBlock(/styles/site.css) %>
<%= Html.CSSBlock(/styles/jquery-ui-1.7.1.css) %>
<%= Html.CSSBlock(/styles/jquery.lightbox-0.5.css) %>
<%= Html.CSSBlock(/styles/ie6.css, 6) %>
<%= Html.CSSBlock(/styles/ie7.css, 7) %>
<asp:ContentPlaceHolder ID=AdditionalCSS runat=server />
</head>
<body>
... BLAH ...
<%= Html.JSBlock(/scripts/jquery-1.3.2.js, /scripts/jquery-1.3.2.min.js) %>
<%= Html.JSBlock(/scripts/jquery-ui-1.7.1.js, /scripts/jquery-ui-1.7.1.min.js) %>
<%= Html.JSBlock(/scripts/jquery.validate.js, /scripts/jquery.validate.min.js) %>
<%= Html.JSBlock(/scripts/jquery.lightbox-0.5.js, /scripts/jquery.lightbox-0.5.min.js) %>
<%= Html.JSBlock(/scripts/global.js, /scripts/global.min.js) %>
<asp:ContentPlaceHolder ID=AdditionalJS runat=server />
</body>


Used in a page like this (which I'm happy with):



<asp:Content ID=signUpContent ContentPlaceHolderID=AdditionalJS runat=server>
<%= Html.JSBlock(/scripts/pages/account.signup.js, /scripts/pages/account.signup.min.js) %>
</asp:Content>





UPDATE: Recommendations for now (late 2013):



I would look at Microsoft ASP.NET's built in Bundling and Minification.


More From » c#

 Answers
53

In the appendix of Professional ASP.NET 3.5 Scott Hanselman talks about Packer for .NET. This will integrate with MSBuild and pack javascript files for production deployments etc.


[#99489] Sunday, May 17, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jaycie

Total Points: 414
Total Questions: 96
Total Answers: 117

Location: Christmas Island
Member since Mon, Oct 19, 2020
4 Years ago
;