Thursday, August 05, 2010
YUI Compressor with GUI
Minification is the process of removing all unnecessary characters from source code such aswhite space characters, new line characters, comments and block delimiters
without changing its functionality. [read more...]
Minified code reduces the amount of data that needs to be transferred through the web server (bandwidth saving).
It may also be used as a kind of obfuscation.
My favorite minification tool is YUI Compressor.
Mostly for CSS (Cascading Style Sheets) and JS (JavaScript).
Let us taka a look what happen when a simple code get minified.
JavaScript - Original Code
function startTime(){ var today=new Date(); var h=today.getHours(); var m=today.getMinutes(); var s=today.getSeconds(); // add a zero in front of numbers<10 m=checkTime(m); s=checkTime(s); document.getElementById('txt').innerHTML=h+":"+m+":"+s; t=setTimeout('startTime()',500); } function checkTime(i){ if (i<10){ i="0" + i; } return i; }JavaScript - Minified
function startTime(){var b=new Date();var d=b.getHours(); var a=b.getMinutes();var c=b.getSeconds();a=checkTime(a); c=checkTime(c);document.getElementById("txt").innerHTML=d+":"+a+":"+c; t=setTimeout("startTime()",500)}function checkTime(a){if(a<10){a="0"+a }return a};CSS - Original Code
body { background-color:#d0e4fe; } h1 { color:orange; text-align:center; } p { font-family:"Times New Roman"; font-size:20px; }CSS - Minfied
body{background-color:#d0e4fe;}h1{color:orange;text-align:center;} p{font-family:"Times New Roman";font-size:20px;}Just to share here, since YUI Compressor don't provide any GUI, I've created one with Java Swing. It has been compiled together with yuicompressor-2.4.2.jar.
You need to have Java installed in order to run this executable JAR.
Download (MD5 : 210176c93d331c50dc19a2dda0ae1c89 JsCssMin.jar)
Using logrotate to rotate and archive log
Previously I found out that rotatelogs cannot replace the rotated logs, I try to find other option.I always come across logrotate whenever trying to search for rotatelogs.
So I give them a try.
1st step is to find it. BTW, I'm on SuSE Linux Enterprise 10.
$ logrotate -ksh: logrotate: not found [No such file or directory]
Since it is not in the path, try to find it by doing this.
$ whereis logrotate logrotate: /usr/sbin/logrotate /etc/logrotate.d /etc/logrotate.conf /usr/share/man/man8/logrotate.8.gz
Now try to run it with full path.
$ /usr/sbin/logrotate
Again, an error occurs.
error: error creating state file /var/lib/logrotate.status: Permission denied
This is because the user that we are currently on don't have write access /var/lib/logrotate.status.
-rw-r--r-- 1 root root 1246 2010-07-28 09:30 logrotate.status
Ask help from system root to change it...
# chmod 666 logrotate.status
...to
-rw-rw-rw- 1 root root 1246 2010-07-28 09:30 logrotate.status
So, now try again.
$ /usr/sbin/logrotate logrotate 3.7.3 - Copyright (C) 1995-2001 Red Hat, Inc. This may be freely redistributed under the terms of the GNU Public License Usage: logrotate [-dfv?] [-d|--debug] [-f|--force] [-m|--mail command] [-s|--state statefile] [-v|--verbose] [-?|--help] [--usage] [OPTION...]
At last. Now create a simple conf like below.
$ cat ./logrotate.conf /home/username/test/mylog { rotate 5 daily copytruncate notifempty compress }
From my observation by triggering it manually (based on configuration above), I found out that it start by compressing the log file and name it mylog.1.gz.
When I trigger it again, it will rename the mylog.1.gz to mylog.2.gz and create a new mylog.1.gz. It will continue to do that but will not exceed mylog.5.gz (rotate 5 from conf file).
-rw-r--r-- 1 user group 348 2010-07-28 15:32 mylog -rw-r--r-- 1 user group 54 2010-07-28 15:32 mylog.1.gz -rw-r--r-- 1 user group 59 2010-07-28 15:32 mylog.2.gz -rw-r--r-- 1 user group 58 2010-07-28 15:32 mylog.3.gz -rw-r--r-- 1 user group 51 2010-07-28 15:32 mylog.4.gz -rw-r--r-- 1 user group 57 2010-07-28 15:32 mylog.5.gz
This is just like what I wanted. It will keep only 5 gz files. Now you can schedule (cron) them accordingly.
Subscribe to:
Posts
(
Atom
)