The difficulty in answering is in not knowing what the server-side resources are that are being returned to the user.
I'll make up something which may serve as an example. Let's say you were developing an application that allowed you to monitor in real-time comments being made by users on your site. We can do several things to make this possible:
- The server keeps track of when comments were added (.created field)
- The API to get the latest comments requires us to specify how old of comments we want
- The view queries and returns only those that have been added since then
models.py
class Comment(models.Model):
text = models.TextField()
created = models.DateTimeField(default=datetime.now())
urls.py
url(r'^comments/latest/(?P<seconds_old>\d+)/$',get_latest_comments),
views.py
def get_latest_comments(request, seconds_old):
"""
Returns comments that have been created since the last given number of seconds
have elapsed.
"""
# Query comments since the past X seconds
comments_since = datetime.datetime.now() - datetime.timedelta(seconds=seconds_old)
comments = Comments.objects.filter(created__gte=comments_since)
# Return serialized data or whatever you're doing with it
return HttpResponse(simplejson.dumps(comments),mimetype='application/json')
On the client-side you get the JSON, check if it has a value, if so enumerate the items, and add the new items to your <div>
tag or whatever.
As you can see, the development of the API to return only recently updated items is going to vary based on what content the server is returning.
From your question it sounds like you want the server to manage identifying what is recently updated, not the client (which is a good strategy). In that case, what you need to do is define:
- How is the server going to keep track of changes (in my example that's done by the 'created' field)
- How is the client going to request those changes
- How is the server going to identify which changes have happened in order to return them to the client via API?