Friday, May 29, 2009

How to use CSS Sprites

Have you ever seen the CSS technique where the “on” and “off” states of a button are contained within the same image and are activated by shifting the background-position? Think of CSS Sprites as an extension of that technique. The difference is that instead of just two or three images being combined into one, you can combine an unlimited number of images into one.

Why combine all those images? Isn’t it quicker to have smaller images?

Nope, it’s not. Back in the day, everybody and their brothers were “slicing” images to make pages load faster. All that technique did was fool the eye to make it look like the page was loading faster by loading bits and pieces all over at once. Each one of those images is a separate HTTP-Request, and the more of those, the less efficient your page is.

Every single image, whether it’s an img tag or an background-image from your CSS is a separate HTTP-Request, so you can image how quickly those requests can wrack up.

OK. So how is it done?

I thought you would never ask. Let’s start by showing the BEFORE example. Notice in the CSS below how the anchor tag does not get a background-image, but each individual class does.

#nav li a {background:none no-repeat left center} #nav li a.item1 {background-image:url('../img/image1.gif')} #nav li a:hover.item1 {background-image:url('../img/image1_over.gif')} #nav li a.item2 {background-image:url('../img/image2.gif')} #nav li a:hover.item2 {background-image:url('../img/image2_over.gif')} ...


Using CSS Sprites, we can really lighten this example up. Instead of having ten separate images for the buttons (five default states and five rollover states), we can literally combine all of them into one big long image. I won’t go into great detail about how this is done, I’ll just give you a basic walkthrough. Create a new image that is as wide as your widest image and and as tall as the combined height of all your images plus X pixels, where X is the number of images you have. Now place you images into this new image, left aligned, one on top of the other with one pixel of white space in between.

Now check out the AFTER example. Notice in the CSS that there is a single background-image applied to the anchor element itself, and the unique classes merely shift the background position with negative Y coordinates.

#nav li a {background-image:url('../img/image_nav.gif')} #nav li a.item1 {background-position:0px 0px} #nav li a:hover.item1 {background-position:0px -72px} #nav li a.item2 {background-position:0px -143px;} #nav li a:hover.item2 {background-position:0px -215px;} ...


We were able to reduce the number of HTTP-Requests by 9 and the total file size of the image(s) by 6.5 KB. That’s a pretty huge improvement for such a little example. Imagine what you could do on a full website.


Simply ZIP all the images you wish to make available as sprites, fill in some basic information about prefixes and offset amounts, and click a button to generate the combined sprite image and CSS code. Sprite Generators, One more

Its very simple, come on lets try to make our websites faster.

Saturday, May 23, 2009

How to Dowload/Upgrade Google Chrome 2.0 Pre Beta

1. Download & Get Google Chrome Stable Release (this step is only required if you dont have Google Chrome)
2. Download and run the Google Chrome Channel Changer
3. Now run Google Chrome Chnnel Changer chromechannel-2.0.exe, and check "Beta: More Stable releases (~Monthly Updates)"
4. Now Start your Google Chrome and Go to Settings->About and Click Update Now and it will start updating your Google Chrome to Google Chrome 2.0156.1.

You need to wait for some time to get Offline Google Chrome Installer.

Google Chrome 2.0 - Better, Faster, Stronger

Google Chrome 2, now out of beta, is less about exciting new features and more about better performance. There's nothing impressive about adding full screen support, form filling or full-page zoom, since all of these features are already available in most browsers.

"Making the web faster continues to be the main area of focus. A new version of WebKit and an update to JavaScript engine, V8, interactive web pages will run even faster. Also it is made sure that JavaScript keeps running fast even when you have lots of tabs open," reveals Google Chrome's blog.

Google's own benchmark shows that the new version runs 30% faster than Chrome 1.0, but it's probably a better idea to test the application for yourself.

I have Chrome 2, and I feel it is faster than any other browsers

Thursday, May 14, 2009

Introducing Webdriver

WebDriver is a clean, fast framework for automated testing of webapps. Why is it needed? And what problems does it solve that existing frameworks don't address?

For example, Selenium, a popular and well established testing framework is a wonderful tool that provides a handy unified interface that works with a large number of browsers, and allows you to write your tests in almost every language you can imagine (from Java or C# through PHP to Erlang!). It was one of the first Open Source projects to bring browser-based testing to the masses, and because it's written in JavaScript it's possible to quickly add support for new browsers that might be released

Like every large project, it's not perfect. Selenium is written in JavaScript which causes a significant weakness: browsers impose a pretty strict security model on any JavaScript that they execute in order to protect a user from malicious scripts. Examples of where this security model makes testing harder are when trying to upload a file (IE prevents JavaScript from changing the value of an INPUT file element) and when trying to navigate between domains (because of the single host origin policy problem).

Additionally, being a mature product, the API for Selenium RC has grown over time, and as it has done so it has become harder to understand how best to use it. For example, it's not immediately obvious whether you should be using "type" instead of "typeKeys" to enter text into a form control. Although it's a question of aesthetics, some find the large API intimidating and difficult to navigate.

WebDriver takes a different approach to solve the same problem as Selenium. Rather than being a JavaScript application running within the browser, it uses whichever mechanism is most appropriate to control the browser. For Firefox, this means that WebDriver is implemented as an extension. For IE, WebDriver makes use of IE's Automation controls. By changing the mechanism used to control the browser, we can circumvent the restrictions placed on the browser by the JavaScript security model. In those cases where automation through the browser isn't enough, WebDriver can make use of facilities offered by the Operating System. For example, on Windows we simulate typing at the OS level, which means we are more closely modeling how the user interacts with the browser, and that we can type into "file" input elements.

With the benefit of hindsight, we have developed a cleaner, Object-based API for WebDriver, rather than follow Selenium's dictionary-based approach. A typical example using WebDriver in Java looks like this:

// Create an instance of WebDriver backed by Firefox
WebDriver driver = new FirefoxDriver();

// Now go to the Google home page

// Find the search box, and (ummm...) search for something
WebElement searchBox = driver.findElement("q"));

// And now display the title of the page
System.out.println("Title: " + driver.getTitle());

Looking at the two frameworks side-by-side, we found that the weaknesses of one are addressed by the strengths of the other. For example, whilst WebDriver's approach to supporting browsers requires a lot of work from the framework developers, Selenium can easily be extended. Conversely, Selenium always requires a real browser, yet WebDriver can make use of an implementation based on HtmlUnit which provides lightweight, super-fast browser emulation. Selenium has good support for many of the common situations you might want to test, but WebDriver's ability to step outside the JavaScript sandbox opens up some interesting possibilities.

These complementary capabilities explain why the two projects are merging: Selenium 2.0 will offer WebDriver's API alongside the traditional Selenium API, and we shall be merging the two implementations to offer a capable, flexible testing framework. One of the benefits of this approach is that there will be an implementation of WebDriver's cleaner APIs backed by the existing Selenium implementation. Although this won't solve the underlying limitations of Selenium's current JavaScript-based approach, it does mean that it becomes easier to test against a broader range of browsers. And the reverse is true; we'll also be emulating the existing Selenium APIs with WebDriver too. This means that teams can make the move to WebDriver's API (and Selenium 2) in a managed and considered way.

If you'd like to give WebDriver a try, it's as easy as downloading the zip files, unpacking them and putting the JARs on your CLASSPATH. For the Pythonistas out there, there's also a version of WebDriver for you, and a C# version is waiting in the wings. The project is hosted at, and, like any project on Google Code, is Open Source (we're using the Apache 2 license) If you need help getting started, the project's wiki contains useful guides, and the WebDriver group is friendly and helpful (something which makes me feel very happy).

So that's WebDriver: a clean, fast framework for automated testing of webapps. We hope you like it as much as we do!

Friday, May 8, 2009

Problems with Flash in IE7?

Maybe your are experiencing this like me: Your IE7 do not show flash content from some websites, even with Flash Player 9 installed on your system, and everything working fine with IE6 or Firefox. I had the same problem, text of my flash was not shown in IE7.

The fact is for some reasons IE7 corrupt Flash Plugin, in result flash detection on websites do not work. And if you try to click on one of the "upgrade Flash plugin" button the browser consider it is already installed.

Here is a solution:

1. Close all open programs
2. Run Adobe Flash Player Uninstaller
3. Reinstall the Flash player

If this do not work you can also try:

- Download the Flash Player standalone installer for Internet Explorer
- Then right-click on the installer and choose "Run as Administrator".

Hope this helps.

Thursday, May 7, 2009

java.sql.SQLException: Io exception: Broken pipe

It seems that connection is broken and we are trying to run a query on it. Try to add a PoolPing query and validate every connection before running it to as application. Now assuming that our ping query really worked and gave us a good connection, there is still a possibility that the connection is really good when you get it from the pool and goes bad while you’re running your app. Following could be the possibilities which could be causing it.
1. Physical connection was killed midstream – That is, some sort of network problem that is causing connections to be dropped after a period of time. If there are firewalls between the app server and database, those are frequently configured to kill connections after a period of time or simply a router problem.
Solution: Track down the problem.
2. The connections to the DB server are being reset and the client (the driver) is not notified. This can happen if the DB server times out and shuts down the connection w/o notifying the client. This can also be caused by firewalls dropping connections.
Solution: Set your connection timeout (in the pool) shorter than the network/DB server timeout.
Set your steady-connection size to 0.