0

What is the mechanism to send the content of a file from a server to the browser only if the file is updated?

For example, I have a file abc.bin on the server which will be updated regularly. Every time the file is updated/modified, the server must send the content to the browser. What method exists to do this?

ArthurN
  • 179
  • 5
  • 15
  • Do you want to push the file to the browser or do you want to redirect to a website if the user visits the download link after he already has downloaded the latest version? – schlingel Oct 30 '13 at 10:13
  • I want to "push" the file to the browser, not redirecting. – ArthurN Oct 30 '13 at 10:16
  • 1
    Have a look at the HTTP Cache headers. You'll be interrested in the "Last-Changed" and "IF-Modified-Since". – Marvin Smit Oct 30 '13 at 10:17
  • @Marvin Smit I don't think the HTTP headers will help him send a push notification to the browser. – schlingel Oct 30 '13 at 10:17
  • For push notification, Have a look at SignalR. You'll probably still have to pull the file with the client after getting a signal from the server. – Marvin Smit Oct 30 '13 at 10:19

1 Answers1

1

Your option is either to write a script which polls for the latest version number and compares it with the latest version number on the client side. If found it downloads the file via a hidden iframe or something like that.

Or you use some web socket based solution. E.g. Pusher offers a service for something like that.

In mobile apps that design is called push notifications. -> use the terminology to find further information.

schlingel
  • 8,560
  • 7
  • 34
  • 62
  • The file exists only on the server. The browser/client needs only the content of the file. I read about server-sent event notifications using EventSource in JavaScript, but obviously this can only send a text notification, not the data. Is there any similar method in PHP/JavaScript that can send data? – ArthurN Oct 30 '13 at 10:28
  • If your data is some kind of ASCII (like XML or JSON) Ajax works out of the box. If you want to process binary data it depends on what data you have there, but maybe this helps you: http://stackoverflow.com/questions/1645847/ajax-binary-response – schlingel Oct 30 '13 at 10:30
  • I think Ajax is triggered by an event on the browser/client (correct me if I'm wrong). In my scenario, the event is on the server (the file is updated). – ArthurN Oct 30 '13 at 10:39
  • 1
    Please have a look on what terms like polling mean. You can put function requesting the file version in a so called timeout loop. The response handler fetches the file when the version changed. Voila. Or you write a web socket which notifies the client when the file changed and this triggers the ajax request. – schlingel Oct 30 '13 at 10:42