How to prevent image from caching in javascript

Many a times when we replace the image with the same name, browser still picks up the old one. Almost every developer faces this issue, then he asks the person to clear the cache by ctrl + F5 or any other means. But is this the solution?

No, So what can we do in this case? There are two solutions,

1 – rename the new image and change the image name in code. But for a dot net developer this is pain because he may have to republish the code and send an upload of the dll again. And giving an upload of dll because of change in image is foolishness, ain’t it?

2 – Another solution is to write a javascript code so that the browser does not pick up image from the cache and loads it everytime. Following is the sample code of how you can try this,

document.getElementById('myimg').src = document.getElementById('myimd').src + '?' + (new Date()).getTime();

You need to make sure this code runs after page has loaded else, it will give an error if that image tag is not yet rendered.

In JQuery for single image code will be

$(document).ready(function(){
$("#myimg").attr('src',$(this).src + '?' + (new Date()).getTime());
});

For all the images

$(document).ready(function(){
jQuery('img').each(function(){
jQuery(this).attr('src',jQuery(this).attr('src')+ '?' + (new Date()).getTime());
});
});

Hope this helps. If you have any more idea please share it with us by dropping a comment.

Opera Unite – Turn Your Computer Into Server

Here is some of the features, I liked about Opera Unite –

Here are some of the applications supported by opera unite. I am going to give example of Opera Unite File Sharing.

List of Opera Unite Applications

List of Opera Unite Applications

Opera Unite file sharing configuration options.

Opera Unite File Sharing Configuration

Opera Unite File Sharing Configuration

This is how your screen will look after file sharing configuration it will show all the files from the folder. You can also see the password option on the right bottom. Once set it will ask the password to the person you send the link to.

Opera Unite File sharing Lists

Opera Unite File sharing Lists

This is the password screen

Opera unite visitors page

Opera unite visitors page

After user enters the correct password he will be shown the list of files and he can download the files.

In the Opera unite whiteboard both the user can share the white board so that the same board is seen by both.

Opera unite dashboard application

Opera unite dashboard application

Opera Unite Inbox application allows you and your friends to upload files on your computer from anywhere.

Opera Unite Inbox Application Settings

Opera Unite Inbox Application Settings

Opera Unite Inbox Application

Opera Unite Inbox Application

Opera Server Application allows you to host application from your machine like online server.

Opera unite application server configuration options

Opera unite application server configuration options

Opera Unite Web Sever Application

Opera Unite Web Sever Application