I have a website that uses a lot of AJAX requests, almost 1 every 2-3 seconds.
One thing I realized is that if I leave the page up for more than 20 minutes, it starts eating through the RAM on the machine with it pulled up (the server never struggles).
//Get the recent activity for the account
function getRecentActivity() {
$.ajax({
url: baseAPIurl + APIversion + "user/activity/",
type: "GET",
data: {
user_id: ****
},
datatype: "json",
success: function (e) {
$("#recent_activity").empty();
if (e.status == "success" && e.results != null) {
$.each(e.results, function (e, t) {
if (t["campaign_type"] == "radio") {
$("#recent_activity").append('<li><a href="/***?id=' + t["campaign_id"] + '"><span class="label label-blue"></span>' + t["campaign_name"] + " - " + t["user_info"]["first_name"] + " " + t["action"] + '<br /><span class="pull-right text-muted small">' + t["timestamp"] + "</span></a></li>");
}
if (t["campaign_type"] == "online") {
$("#recent_activity").append('<li><a href="/***?id=' + t["campaign_id"] + '"><span class="label label-blue"></span>' + t["campaign_name"] + " - " + t["user_info"]["first_name"] + " " + t["action"] + '<br /><span class="pull-right text-muted small">' + t["timestamp"] + "</span></a></li>");
}
})
} else {
$("#recent_activity").append('<li><a href="#"><span class="label label-blue"></span>No Recent Activity<span class="pull-right text-muted small"> </span></a></li>');
}
}
})
}
What is a better way to make so many requests, and not use 1GB or more of RAM?