DCSIMG
ASP.NET MVC Razor CSS and Javascript Compress and Manager - Rotem Bloom's Blog

Rotem Bloom's Blog

Share knowledge on .NET and web development

News

About Me

Glad to help and share knowledge on .NET and also huge fan of Dream Theater.

Contact me via messenger

View Rotem Bloom's profile on LinkedIn

Dream Theater Pics

Blogs I Read

ASP.NET MVC Razor CSS and Javascript Compress and Manager

Hi,

If you are ASP.NET MVC Razor developer and you are looking for a nice solution to Combine, Compress and Manage your CSS and JavaScript files,

Well SquishIt can fit your needs.

Razor Code Sample:

@MvcHtmlString.Create(
  SquishIt
.Framework.Bundle.Css()
   
.Add("~/media/css/reset.css")
   
.Add("~/media/css/style.less")
   
.Add("~/media/css/handheld.css")
   
.Render("~/media/css/combined_#.css"))

@MvcHtmlString.Create(
  SquishIt
.Framework.Bundle.JavaScript()
   
.Add("~/media/js/geo.js")
   
.Add("~/media/js/jquery-1.4.4.js")
   
.Add("~/media/js/jquery.unobtrusive-ajax.js")
   
.Add("~/media/js/jquery.validate.js")
   
.Add("~/media/js/jquery.validate.unobtrusive.js")
   
.Render("~/media/js/combined_#.js"))

Output looks like this:

<link rel="stylesheet" type="text/css" href="/media/css/combined_312454.css" />
<script type="text/javascript" href="/media/js/combined_312454.js"></script>

You can read more here.

We are using SquishIt on the company I work and it look like a really nice and useful solution.

I hope you will find it useful on your company or project also :-)

Yours,

Rotem

Comments

ASP.NET MVC Razor CSS and Javascript Compress and Manager – Rotem … said:

Pingback from  ASP.NET MVC Razor CSS and Javascript Compress and Manager &#8211; Rotem &#8230;

# August 9, 2011 4:22 PM

xhtml css templates – ASP.NET MVC Razor CSS and Javascript Compress and Manager – Rotem … | XHTML CSS - Style sheet and html programming tutorial and guides said:

Pingback from  xhtml css templates &#8211; ASP.NET MVC Razor CSS and Javascript Compress and Manager &#8211; Rotem &#8230; | XHTML CSS - Style sheet and html programming tutorial and guides

# August 9, 2011 4:25 PM

Stanislav said:

Maybe it's only me, but I'd actually prefer to write the same functionality as a separate http module.

# August 14, 2011 10:17 PM

Rotem Bloom said:

Hi Stanislav,

Thanks 4 your comment.

Can you share your HttpModule solution?

With a solution based on HttpModule you need to make sure your are caching your JS result and not compressing and open the JS files on every request.

Rotem

# August 16, 2011 11:53 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: