Thursday, November 24, 2005

Cache-Busting with Javascript

Got an opportunity to work with Javascript. On reading, got this information.

What it is?

As we all know, when we are browsing the pages fetched by the browser will be stored in the browser's cache. If we want to get the page from the server and not from the cache, using Javascript, it is very simple. Just add a random key-value pair to the URL. This should be unique for each request.

How to do?
Set your request URL as :
URL +"?rand=" + (Math.random() * 99999999);

How it works?

I assume that, the browser MAY maintain a key-value pair (Something like a HashTable), that contains the "URL of the requested page" as the key and the "contents of the page" as its value. So when a request is made, it first checks its cache and if it finds a page it returns it, else fetches from the server. In our case, since random() generates different values for each call, the browser will assume that this is a new request for a page and fetches it from the server. This in no way affect the server. Since the server may not know about the additional parameter, it will discard the variable.

Wednesday, November 09, 2005

printf(_"string") - What does that "_" mean?

Most of us might have encountered a code like the one mentioned above. What does this mean? Goooogling gave me its meaning.

Actually, a macro by name _(str) will be defined as follows:
#define _(str) gettext(str)

What gettext() does?

The gettext function translates the "str" from the natural language message into the user's language by looking up the translation in a message catalog.
From this, what I understand is, suppose I am using Latin language in my machine. And the string "str" is in English. So whenever printing, the gettext() translates English to Latin gives it to printf(). So I'll be seeing the messages in Latin.

Hope Microsoft also uses a similar kind of macro "_T" for displaying strings in multi-byte format.