Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

compressing .js and .css files on push of the website

I am not even sure if something like I want is possible, so I am asking you guys to just let me know if anyone did that before. So, my goal is to when I click on "Publish" website in VS2010, to have all javascript files compressed into one, same with css and then in my layout file change the references from all different js and css files to only those two merged ones. Is that doable? Or maybe it's doable but in more manual way?

Of course the goal here is to have only two calls to external files on the website, but when I develop I need to see all files so that I can actually work with it. I guess I could do it manually before each push, but I'd rather have it done automatically using some script or something. I didn't try anything yet, and I am not looking for ready solution, I am just looking to get to know the problem better and maybe some tips.

Thanks a lot!

like image 720
bobek Avatar asked Mar 16 '12 13:03

bobek


People also ask

How do I compress CSS and JS files?

To minify CSS, try CSSNano and csso. To minify JavaScript, try UglifyJS. The Closure Compiler is also very effective. You can create a build process that uses these tools to minify and rename the development files and save them to a production directory.

Can you compress JavaScript files?

Javascript code can be compressed in one or more of the following ways: By removing white spaces and indentation. By shortening variable names to single characters. By removing new line characters.

Can CSS be compressed?

The more complex and larger the CSS files are, the longer the visitor has to wait until the site has completely finished loading. By compressing the CSS, you can reduce the size of the CSS file and increase the performance of your website.


1 Answers

This is built into ASP.net 4.5. But in the mean time, you should look at the following projects

  • YUI Compressor
    • The objective of this project is to compress any Javascript and Cascading Style Sheets to an efficient level that works exactly as the original source, before it was minified.
  • Cassette
    • Cassette automatically sorts, concatenates, minifies, caches and versions all your JavaScript, CoffeeScript, CSS, LESS and HTML templates.
  • RequestReduce
    • Super Simple Auto Spriting, Minification and Bundling solution
    • No need to tell RequestReduce where your resources are
    • Your CSS and Javascript can be anywhere - even on an external host
    • RequestReduce finds them at runtime automatically
  • SquishIt
    • SquishIt lets you squish some JavaScript and CSS. And also some LESS and CoffeeScript.
  • Combres
    • .NET library which enables minification, compression, combination, and caching of JavaScript and CSS resources for ASP.NET and ASP.NET MVC web applications. Simply put, it helps your applications rank better with YSlow and PageSpeed.
  • Chirpy
    • Mashes, minifies, and validates your javascript, stylesheet, and dotless files. Chirpy can also auto-update T4MVC and other T4 templates.

Scott Hanselman wrote a good overview blog post about this topic a while back.

like image 94
jessegavin Avatar answered Sep 23 '22 08:09

jessegavin