10

What is the best way to compress or minify jQuery, javascript and CSS files?

I am new with the compressions and minify features of web development please help me.

1

4 Answers 4

4

I personally use Yahoo Compressor and would recommend it. Why? Because it works.

An example of how to execute it at the command line:

java -jar yuicompressor-2.4.7.jar javascriptfile.js -o outputfile.js --charset utf-8

Do the same on a CSS file:

java -jar yuicompressor-2.4.7.jar style.css -o outputstyle.css --charset utf-8

Actually, I just realized I use a thing called htmlcompressor for HTML files:

java -jar htmlcompressor-1.5.3.jar hmlfile.html --remove-intertag-spaces --compress-js

Google's Closure Compiler looks good as well, but I have not personally used it yet so I'm not sure if it does CSS and HTML as well as Javascript.

Sign up to request clarification or add additional context in comments.

2 Comments

Please could you explain a little why and how to implement it?
I too use yuicompressor in my project. Google Closure is js-only and it's awesome if you write high-quality code and annotate everything with closure annotations, other than that it's result doesn't differ much from yuicompressor, but yui is a lot faster.
0

I recommend using a tool which is provided or can integrate with your framework/toolset, to handle this automatically.

If you are using django, I recommend spaceless template tag or django-htmlmin app for html templates and django_compressor for js/css.

Comments

0

You can try http://www.jasob.com/ it allow you to Obfuscation and compression for JS and CSS

Comments

0

You can use require.js optimizer within node.js or Java, which supports both optimize the code itself and also minimize it [ If you are using require.js ] You can use Google Web Toolkit restful api to increase performance of your codes and also for minifying purposes You can use ASP.NET bundling for minifying You can use Grunt to automate you unit tests and minifying

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.