Quantcast
Viewing latest article 2
Browse Latest Browse All 10

JSOM: Last Modified Date of a List

The data transfer between server and client can heavily affect the performance. One of the measures to reduce the amount data transferred from the server to the client is storing data on the client. In many modern browsers we can use html5 localStorage. Even in older browsers there are ways to store data.

I would recommend a nice js lib called amplify.js. The interface is much easier, then:

amplify.store("key", { title: "value" });

It comes in nicely, if we have much data which we get with JSOM. But we have to care about eventual changes to list items done after we got them the last time.

So we have to store the last modified date. This property is also available in JSOM:

var ctx = SP.ClientContext.get_current();
var web = ctx.get_web();
var lists = web.get_lists();
var list = lists.getByTitle("Tasks");
ctx.load(list, "LastItemModifiedDate");
ctx.executeQueryAsync(
	function() {
		var lastmodified = list.get_lastItemModifiedDate();
	},
	function() {}
);

Be sure you load only the properties you need:

ctx.load(list, "LastItemModifiedDate");

I took a screenshot to show the difference:

Image may be NSFW.
Clik here to view.

Next time we want to load our items, we can check if we have them saved locally and get the last modified date of the list. If this hasn’t changed, just load from the localStorage.

Another property to keep an eye for is “LastItemDeletedDate”…


Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.

Viewing latest article 2
Browse Latest Browse All 10

Trending Articles