Thursday, August 26, 2010

Bridge over troubled waters..



When you're weary, feeling small,
When tears are in your eyes, I will dry them all;
I'm on your side. when times get rough
And friends just cant be found,
Like a bridge over troubled water
I will lay me down.
Like a bridge over troubled water
I will lay me down.

When you're down and out,
When you're on the street,
When evening falls so hard
I will comfort you.
Ill take your part.
When darkness comes
And pains is all around,
Like a bridge over troubled water
I will lay me down.
Like a bridge over troubled water
I will lay me down.

Sail on silver girl,
Sail on by.
Your time has come to shine.
All your dreams are on their way.
See how they shine.
If you need a friend
Im sailing right behind.
Like a bridge over troubled water
I will ease your mind.
Like a bridge over troubled water
I will ease your mind.

Friday, August 20, 2010

Android scripting with python

A good article describing how to do android scripting with python. I have no idea about how to program using python. But given that this is one of the languages that you can use to code for android, may be i would just go ahead and take a look at it.

Here is the link.

OAuth and twitter. A nice article

Twitter has closed down basic authentication and started using OAuth. A nice article explaining OAuth and twitter.Over here. There are also links and resources to OAuth and what it is from the page.

Custom dojo builds

Most of us would like to extend dojo widgets/make changes to dojo code and rebuld our widgets along with rest of the dojo code. Another reason would be to optimize load times for your dojo widgets. Given that the widgets are loaded lazily, you would want to load a compressed javascript dojo file which contains all the widgets you need in a compressed format.
Here is how you could go about doing a custom dojo build.

Download the dojo source from the dojo download site. 
 Unzip it, and you should find a util directory in there. Go to util/buildscripts/profiles .
Now you need to create your own profile file which you will give it as an input to the build process.
Lets call it foo.profile.js.
It could look something like this:

dependencies = {
    layers: [
        {
            name: "customdojo.js",
            dependencies: [
                "dijit.Dialog",
                "dijit.layout.ContentPane",
                "dijit.form.CheckBox",
                "dijit.form.ComboBox",
                "dijit.form.TextBox",
                "dijit.ProgressBar",
                "foo.widget.button",
                "foo.widget.table",
            ]
        }
    ],
    prefixes: [
        [ "dijit", "../dijit" ],
        [ "dojox", "../dojox" ],
        ["foo","../../web/javascript/foo"]
    ]
}

You would notice that the contents of this file are in json format. The first thing of importance is the attribute layers.name which defines the name of the output file that is produced as a part of the dojo build process. right now it is called as customdojo.js . This is followed by a list of widgets that you want to be a part of the customdojo.js file. You should notice a couple of custom widgets too as a part of the build.
Note that the prefixes define where to find the dojo widgets specified above. They point to the directories path relative to the "util" directory. Hennce, dijit resides in "../dijit" and my foo widgets reside in the "../../web/javascript/foo".
Now , the next thing is your build command.
After you have saved the above file as say foo.profile.js, go to one level above to util/buildscripts/ and run the "build.bat" or the "build.sh" file depending on which platform you are in.

If you are in linux you could do something like

build.sh profile=foo mini=true action=release version=x.x.x optimize=shrinksafe
 copyTests=false cssOptimize=comments

This should produce a "release" directory containing the customized dojo build. You could probably also gzip your resultant output as discussed in one of the blog entries earlier.
It would be much more convenient if we actually automated this whole build process with an ant task. I'll try to talk about that in my next blog entry.

Thursday, August 19, 2010

YUI Theater

Check out this link YUI Theater. It contains some really good videos that you can watch in your leisure time on front end web application development.

Gzip javascript files

To gzip your javascript files, you can use the following ant task (you can add dependencies to your task as needed).
    <target name="gzipJavascript">
           
<gzip destfile="${destination-dir}/combined.js.gz" src="${path-to-your-js-file}/combined.js">
    </gzip>
</target>


and just invoke this from your ant task. Simple.

The output of the gzip process will now be stored in your prescribed directory. I usually store the un-gzipped ones and the gzipped ones in the same resultant directory.


The next thing you need to do is to make sure that your server can serve this gzipped content to the client. To do that, you will have to modify your server.xml appropriately (its location depends on which application server/web server) that you are using. I have been using jboss and hence i will describe what i did for jboss to be able to do it.

In your <jboss-install-location>/server/<domain>/deploy/jboss-web.deployer/server.xml

Put in the following code (the modified parts are in bold)

    <connector  port="8080" address="${jboss.bnd.address}"
         maxThreads="250" maxHttpHeaderSize="8192"
         emptySessionPath="true" protocol="HTTP/1.1"
         enableLookups="false" redirectPort="8443" acceptCount="100"
         compression="on"
compressableMimeType="text/html,text/xml,text/css,text/javascript, application/x-javascript,application/javascript"
         connectionTimeout="20000" disableUploadTimeout="true" />
Now, the next step is to include the javascript file in your web page.





If i have web/javascript/appname/combined.js and web/javascript/appname/combined.js.gz as a result of my various stages of the build process, my javascript include will look something like this




        <script src="/web/javascript/appname/combined.js" type="text/javascript">
</script>     



Note that i specify the include normally as a "text/javascript" and i really dont specify the ".gz" suffix. The application server will analyze the incoming request and if the client can handle gzipped compressed files, then it will server the gzipped files. Else it will serve the normal file.


Since javascript load is blocking call, you should notice load times reduce drastically once you do this.you can also do this compression for other resources such as your html/css files too.

Javascript optimization for web applications

There are a number ways in which you can go about optimizing your web application. This is one of the places where you could probably find the holy grail.

Javascript download time is one of the major bottlenecks for web applications. Let me explain how i managed to reduce the download time of my incredibly huge and chunked javascript files to reduce load times.


While in development stages, it is nice and developer friendly to modularize javascript into various files and folders, the load time gets really ugly when you put the app into production. Given that most of us various web frameworks/libraries like dojo, jquery, ext-js etc.. which themselves load a number of javascript files in turn depending on their usage, it is better to optimize your javascript.
Combine your javascript


This should be pretty simple. You can start off by writing a simple java class which takes in a list of files as an argument. This would then read all the contents of the files and write them out into a simple file. You could call that "combined.js". You can call this as a task from your build script such as ant

Compress the resultant javascript (minification)

The combination process just produces a huge single bulky file. This will result in reducing the number of HTTP requests for javascript files but you would still have to deal with the size of the javascript file. There are number of tools which allow you to compress your javascript files. The compression basically minifies your code in the sense that all the formatting in the code (spacing/indenting even carriage returns) is removed out and variable names are "optimized". You cannot probably debug using this compressed version of javascript. I have been using YUI compressor in my project with much satisfaction. A number of resources are available on how to perform this and hence i am not going to blog about it here. You can probably find a good article on how to use the yui compressor in your ant task over here

GZip javascript

One of the final steps you could try to do is to gzip the resulting javascript. This really reduces the size of the javascript file that is to be downloaded to the client. I could manage to compress a 500 kb(approx) javascript file to about 90 kb. I will talk about gzip process in my next blog.

Since javascript resources are one of the main bottlenecks in an application loading process (along with heavy images), the above three steps should help you speed up your application load time.

Note that you could also apply above process for your CSS files if they start to become too large or even gzip your html files if they are large enough and take a while to download.

Back with a bang.. well atleast a whimper

Its been a while since i actually blogged over here.. Not surprising given that blogging is a tedious effort requiring a lot of time and dedication over a period of time which i actually dont have. And given the fact that most of the times i am actually the only one that actually reads back my blogs, it isnt quite the motivation i need to dedicate the necessary amount of time and resources. Of late though, i think i seem to have come across a lot of exciting stuff on the internet that i share on facebook and twitter.. (hey thats the latest fad on the internet.. blogs are for grampies!) But then i find that once in a while its really necessary to record those "findings" on internet in some place permanent (nopes.. nada.. a diary wont do.. dont remember where i kept the last diary) and book marks on del.icio.us just tend to rot in the web.

This re-entry into the blog-o-sphere is supposed to record my daily accidental findings at work and other interesting things that i come across over here.. I can come and look over it later and reminisce all the greatness around rather than them being lost in stream of updates from friends and weird apps from facebook and twitter.. Lets see how it goes