Hi,
Which good ways exists to reload front page by server every time that new article placed by editor in front page for (news popular website like fox.com, cnn.com)?
Thanks
Hi,
Which good ways exists to reload front page by server every time that new article placed by editor in front page for (news popular website like fox.com, cnn.com)?
Thanks
What you want is an AJAX call on your front page that queries the server for new articles every few minutes and if the server returns a new article the Javascript should then display it to the page.
The poor man's alternative to AJAX (sheesh, does every two-bit Web site have to be Web 2.0 these days??) is simply inserting an HTML refresh command into the page. This is documented all over the Web; I Google for it whenever I need it, and keep forgetting how.
It's dead simple and works even if the user has JavaScript disabled. On the downside, it does refresh the entire page.
You are looking for some asynchronous client/server communication.
GWT and GWT-RPC:
Since you are on Java, I recommend you have a look at GWT, will simplify your "AJAX" work with its GWT-RPC. In GWT you use Java language on both the server-side and the client-side (compiled to JavaScript), and will handle all the implementation details on the asynchronous communication under the hood.
To do the polling here, you can have a timer on the client-side (on the webpage) that will call a method that you have written on the server to give the data, can either be a String
that represents some news, or even encapsulate it into a News
class, with title, summary, body, and timestamp etc. The News
class will then have to be in a shared (between client and server) Java package, so the implementation can be used on both sides without having you duplicating code.
GWT Comet:
This gwt-comet library provides an efficient Comet implementation for GWT.
The library implements Comet by streaming messages over long lived HTTP requests to minimise latency and bandwidth requirements and maximise the throughput. This is opposed to many other implementations which use polling or long polling techniques.