I'm using jFeed to parse an RSS feed, but I'm thinking now how I can track changes on interval based checking. How would one efficiently check if there are new items in a feed compared to the previous load? Unfortunately I can't use the RSS 2.0 last updated parameter, as it doesn't exist.
Asked
Active
Viewed 396 times
1 Answers
1
Fixed it! See the following solution:
//namespace for vars
$.feedentries = {
lastKnownEntry : ""
};
jQuery.getFeed({
url: 'proxy.php?url='+encodeURIComponent(url),
success: function(data) {
//if new iterate through it until we've found the last know entry
if(data.items[0].title!==$.feedentries.lastKnownEntry){
var entries = "";
$.each(data.items, function(i, feed) {
if(feed.title!==$.feedentries.lastKnownEntry){
entries += '<div class="rss-entry">'+feed.title+'<div class="time"><a href="'+feed.link+'">'+feed.updated+"</a></div></div>\n";
//remove last element, prevents from overflowing
$(id+" .rss-entry:last-child").remove();
} else {
//stop once we reach last known entry
return false;
}
});
//insert into DOM
$(id).prepend(entries);
//write new last known rss title
$.feedentries.lastKnownEntry = data.items[0].title;
}
}
});

FLX
- 4,634
- 14
- 47
- 60