0

I am running a slideshow using the javascript code below on my server Ubuntu 12.04.1. The problem, when I change the name of the images, then I get unlimited server responses 304 (not modified) on Chrome network tool. But, when I clear the browser history (cache), I get everything fine and just 5 network requests from Cache and not more like the screen shot attached.

I wonder why this happen and how to solve it? Screen shot attached for your kind reference! Would greatly appreciate if you hint me how to solve these unlimited requests? Thank you!

In the page index.php:

<SCRIPT>
//set image paths
src = ["ic/photo1.jpg", "ic/photo2.jpg", "ic/photo3.jpg", "ic/photo4.jpg", "ic/photo5.jpg"]

//set duration for each image
duration = 4;

ads=[]; ct=0;

function switchAd(){
    var n=(ct+1)%src.length;
    if (ads[n] && (ads[n].complete || ads[n].complete==null)) {
        document["Ad_Image"].src = ads[ct=n].src;
    }

    ads[n=(ct+1)%src.length] = new Image;
    ads[n].src = src[n];
    setTimeout("switchAd()",duration*1000);
}

onload = function(){
    if (document.images)
    switchAd();
}

//-->
</SCRIPT>

<IMG NAME="Ad_Image" SRC="ic/photo1.jpg" BORDER=0>

enter image description here

Sammitch
  • 30,782
  • 7
  • 50
  • 77
moderns
  • 650
  • 10
  • 23
  • What do you mean, "unlimited"? You're getting the images from the cache, isn't that good? – bfavaretto Oct 23 '13 at 17:01
  • @bfavaretto: if you notice on left bottom of the screen shot, 38 requests and if I keep it for one hour, it might reach 100 requests! So when the user opens my website for 2 hours, then 200 requests will be sent and received! But when I get it from the cache, i get just 5 requests with a status 200! – moderns Oct 23 '13 at 17:03
  • Are you high? Do you not know what a `304 Not Modified` response means? – Sammitch Oct 23 '13 at 17:05
  • @Sammitch: I know! But why when changing the name I get this? It makes delay when viewing the image of the slideshow! – moderns Oct 23 '13 at 17:07
  • Please help me to get red of these responses! I don't need the 304 response! How? – moderns Oct 23 '13 at 17:10
  • I'ma just assume this is a JS thing and untag php, because this clearly has nothing to do with php. – Sammitch Oct 23 '13 at 17:10
  • I believe that means the "expires" and/or cache control max age from the first request has expired, so the browser starts pinging the server for updates. Since there are no updates, it responds with a 304. Try sending cache-control headers with your 304, see http://stackoverflow.com/a/1955634/825789 – bfavaretto Oct 23 '13 at 17:14
  • @bfavaretto: I have tried that and went through the post you put, but didn't work unfortunately :( – moderns Oct 23 '13 at 17:19

1 Answers1

0

I have solved this question buy calling the image once from the server instead of calling it each time to view, i.e. I added the images in the document, then added a src to each of one (ONCE - this means to call them once from server), then for each repetition, I show one image and hide the others! Because if I give a src to each image when viewing, then the server might be slow when the server requests to see if the image has been modified last time called (304 response), and this results in delaying the view! Thank you :)

moderns
  • 650
  • 10
  • 23