To enhance performance and minimize bandwidth usage, avoid using cookies
as noted in the comments. Instead, consider utilizing local storage within the browser to store information about the last image used. By incrementing this value at the start of a new session, you can easily display the next image.
Personally, I have had success utilizing jStorage in my projects for similar purposes.
You can save details such as the current image being shown and possibly a session ID in the user's browser storage. Subsequently, you may monitor changes in the session ID to switch to a different image accordingly.
var image = $.jStorage.get("image", 0);
var session_id = $.jStorage.get("session", "insert current session id here");
if(session_id !== "current session id")
{
image = (image < 50) ? 0 : image+1;
$.jStorage.set("image",image);
$.jStorage.set("session","current session id");
}
// utilize the 'image' variable to set the background
UPDATE:
For improved efficiency, refrain from embedding this JavaScript code directly in every web page. Opt for placing it on an ASP.NET page that serves as a Javascript content type, allowing you to load it through the page's header section. This approach ensures that browser caching does not interfere with the script when the session undergoes changes.