Category Archives: web development

Browsers, pixels and graphic rendering!

These days I noticed something quite interesting in rendering DOM elements by a sample browser. In my case this was Firefox, but whatever the browser was this happens always.

Let me explain you what was the case. I have to render 200 DIV elements, each with 2 pixels width and 30 pixels height. Thus you got something like a scale.

So far so good. The problem is that if you get some random width for the scale as the browser can be resized. If you’d like something like random space (gap) between the scale bars you get something like 7,35 pixels between every two bars.

Of course the browser cannot use non integer pixels so it starts to render gaps which are 7 pixels wide and in every few pixels it renders 8 pixel single gap. Thus he corrects this problem.

My advice is – don’t make the browser think and round the pixels. Use fixed integers to make browser flow faster. You can fix the whole width to be multiple of 200 pixels which is the number of bars.

object and embed tag position in IE

What is OK?

If you’ve written at least once the OBJECT and EMBED tags, without copy/paste you may have been noticed that the place of the EMBED tag is a bit strange. Actually after the OBJECT tag, comes the PARAM sequence, that simply defines different parameters for the flash movie.

And what looks strange?

The strange thing in all this is that the EMBED tag, which in fact is only one, instead of the case with all the parameters of the OBJECT, is displayed just before the closing of the OJBECT tag.

Experimenting …

What if the embed tag is outside of the OBJECT opening and closing tags. Actually only IE understands this as a problem. Than it displays the move twice!

That’s why the place of the EMBED is just before closing the OBJECT tag. In that case MSIE doesn’t “see” the EMBED and displays everything correctly!

CSS Sprites – common mistakes

CSS Sprites

Although there are so many resources about CSS sprites and where they should be used I still think their usage is misunderstood.

The big problem is that many people use the sprite in a completely wrong way. When used properly the sprite can be really helpful, especially for a large scale site.

The mistake

When you read about sprites and you understand you must use only one image you start doing the big mistake. Let’s assume we’ve one image for the backgrounds of three div elements:

.a {
    background: url(sprite.png) 10px 10px no-repeat;
}
.b {
    background: url(sprite.png) 20px 20px no-repeat;
}
.c {
    background: url(sprite.png) 30px 30px no-repeat;
}
<div class="a"></div>
<div class="b"></div>
<div class="c"></div>

Now even with this simple example there is one sprite image but the browser makes three requests for this image, which is really bad!

The solution

How about making it the right way with a simple change:

.sprite {
    background-image:url(sprite.png);
    background-repeat: no-repeat;
}
.a {
    background-position:0px 0px;
}
.b {
    background-position:10px 10px;
}
.c {
    background-position:20px 20px;
}

and a little bit different markup:

<div class="sprite a"></div>
<div class="sprite b"></div>
<div class="sprite c"></div>

and this is where the sprites are really useful. Now the browser makes only one request and your site is ready for the big world.

jQuery debug plugin

Console.log()

Almost everybody using Firebug extension of Firefox is familiar with console object and in common with console.log method, who’s taking an object parameter and dumps it into the Firebug console. It’s perfect for debugging and it’s really useful.The problem is that if you don’t have Firebug installed or it’s disabled the console object is undefined. The same may occur if you’re using other browser. That’s why I decided to make a simple plugin for jQuery with the $.log interface which checks for the console and opera objects and if they don’t exists just alert the message. It’s nothing special.

Continue reading jQuery debug plugin →

starting cronjob on Mac

It’s as easy as starting a cronjob on Linux

Yeah it shouldn’t be different. You simply execute in the terminal the well known command

crontab -e

to start editing your crontab file. The crontab (cron table) in breve is the place where you put the scripts you want to automate. Its exactly the same syntax as on Linux.

Than you restart the cron process

The most simple way is to force quit it from the activity monitor, the process’s called cron as you can see on the following image.