Minified Code Javascript, css with YUI Compressor - The Yahoo! JavaScript and CSS Compressor



The YUI Compressor is a JavaScript compressor which, in addition to removing comments and white-spaces, obfuscates local variables using the smallest possible variable name. This obfuscation is safe, even when using constructs such as 'eval' or 'with' (although the compression is not optimal in those cases) Compared to jsmin, the average savings is around 20%.

The YUI Compressor is also able to safely compress CSS files. The decision on which compressor is being used is made on the file extension (js or css)

To minify resources (javascript/ css), please download the jar file at https://github.com/yui/yuicompressor/releases, then open terminal and run:
$ java -jar /path/to/yuicompressor.jar example.js -o example.min.js
$ java -jar /path/to/yuicompressor.jar example.css -o example.min.css


You also can use the online JavaScript/CSS/HTML compressor at http://refresh-sf.com/

Eg:
jQuery.noConflict();
(function($) {
    $(function(){
        $.fn.addNoDataRemoteClass = function (options) {
            var defaults = {
                elementSelector : ['footer', '.block-login', '.tabs', '.links', '.content-wrapper article'],
                className : 'no-data-remote'
            }
            var options = $.extend(defaults, options);
            var that = $(this);
            var n = options.elementSelector.length;
            for(i = 0; i < n; i++) {
                that.find(options.elementSelector[i]).find('a').addClass(options.className);
            }
            that.find('a[href="javascript:void(0)"]').addClass(options.className);
            that.find('a[href=""]').addClass(options.className);
            that.find('a[href="#"]').addClass(options.className);
        }
    });
})(jQuery);


will be:
jQuery.noConflict();(function(a){a(function(){a.fn.addNoDataRemoteClass=function(b){var d={elementSelector:["footer",".block-login",".tabs",".links",".content-wrapper article"],className:"no-data-remote"};var b=a.extend(d,b);var c=a(this);var e=b.elementSelector.length;for(i=0;i<e;i++){c.find(b.elementSelector[i]).find("a").addClass(b.className)}c.find('a[href="javascript:void(0)"]').addClass(b.className);c.find('a[href=""]').addClass(b.className);c.find('a[href="#"]').addClass(b.className)}})})(jQuery);

No comments:

Post a Comment