es131245 Posted April 17, 2014 Share Posted April 17, 2014 (edited) Server runs shell script that updates image on the site every 3 seconds. Its makes "framed image" for the site. Browser part is: setInterval(function(){$('#picID').attr('src','/images/URL.jpg?'+new Date().getTime());},3000); It works fine but update script doent work all the time. So i want to find a way for javascript to check if image on the site differ from downloaded one. Is it posible to check if it differ without downloading whole image? Like check if file size have changed? Moreover is there a "better" method of forcing image to download instead of "+new Date().getTime()"? Edited April 17, 2014 by es131245 Link to comment Share on other sites More sharing options...
davej Posted April 17, 2014 Share Posted April 17, 2014 What if a browser is downloading the image when the server changes the image? Maybe Ajax could be used to get all the timers synchronized? Link to comment Share on other sites More sharing options...
es131245 Posted April 17, 2014 Author Share Posted April 17, 2014 What if a browser is downloading the image when the server changes the image? I'm getting corrupted images in that situation, but i dont have solution for that so i going to leave it as it is. Maybe Ajax could be used to get all the timers synchronized? The situation is that script doent work all the time. So I just need to let js in browser know when its useless to update picture every 3 seconds. How could timer help here? There are no time dependance here. Link to comment Share on other sites More sharing options...
davej Posted April 17, 2014 Share Posted April 17, 2014 Is this a rotating set of images or something like a framegrab of a live webcam? The server changes the image every three seconds. When a browser does a pageload it could submit an ajax request for the number of milliseconds until the next image change. The browser could then get the timer to load the images in sync with the server imagefile updates. Link to comment Share on other sites More sharing options...
es131245 Posted April 18, 2014 Author Share Posted April 18, 2014 Is this a rotating set of images or something like a framegrab of a live webcam? Yes it is. The browser could then get the timer to load the images in sync with the server imagefile updates. Images are updated by shell script on a separate machine! There aren't any timers here. All i can do is to get mtime by php then page loads for synchronization. But i don't care much about synchronization. All i want is a part of javascript/jquery code that checks if there is an newer image at all (if there is a point of loading large image at all). Script might be turned off and i need to check that. On web cam example. Javascript should check if camera works for saving watcher from loading the same image tons of times. Link to comment Share on other sites More sharing options...
davej Posted April 18, 2014 Share Posted April 18, 2014 Javascript can't do that. Only server-side code can look at the file and notice that the file timestamp has changed. It can then tell the browser via Ajax. Link to comment Share on other sites More sharing options...
es131245 Posted April 18, 2014 Author Share Posted April 18, 2014 Javascript can't do that. Only server-side code can look at the file and notice that the file timestamp has changed. It can then tell the browser via Ajax. Or php can print mtime while page loads. Can't check exact file size (if changed) and base64 doent seem to too. Link to comment Share on other sites More sharing options...
davej Posted April 18, 2014 Share Posted April 18, 2014 Yes, Php could simply render the timestamp if the page loads quickly, however if the page takes a second to load then this would be inaccurate. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now