This project has moved and is read-only. For the latest updates, please go here.

Better User Scraping

Jan 23, 2012 at 10:03 AM


I've been using SPServices to develop web applications hosted in SharePoint document libraries, but not embedded in SharePoint pages. It has worked very well, but I've always been bothered by the way SPGetCurrentUser will load all supporting files for the userdisp.aspx page. I do not like this because it can result in loading unwanted/unneeded scripts or CSS, and it requires far more load time than necessary in situations where the SharePoint-related files (JS, CSS, Pics, etc) are not already loaded.

These extra files are loaded because of the jQuery call on line 2196 of SPServices 0.7.0. jQuery transforms the HTML into DOM elements in order to process it (also costly), thereby causing the browser to load all references. Therefore, since neither the transformation nor the references are needed to obtain the information, I changed the function to process the text response as a string. Now, it only loads the needed file, processes it faster than before (no DOM transformation or jQuery loops), and is smaller than the original.

For SPServices 0.7.0:

Line 2188 is removed, and lines 2195 - 2218 are replaced with:

complete: function (t) {
	t = t.responseText.substr(t.responseText.indexOf('FieldInternalName="' + opt.fieldName + '"'));
	t = t.substring(t.indexOf('FieldType="') + 11, t.indexOf('</td')).replace('&#160;', '');
	thisField = (t.indexOf("<div") > -1 ?  t.match(/<div.*?>(.+)<\/div>/) || [,''] : t.match(/src="([^"]+)"/) || t.match(/href="([^"]+)"/) || [,t.substr(t.indexOf('-->') + 3).trim()])[1];

Additionally, this returns proper results for SPFieldURL types that are not a picture.


Jan 25, 2012 at 10:11 PM
Edited Mar 26, 2012 at 5:49 PM

Thanks, Stephen.

I haven't had a chance to take a look at this yet, but it seems to make good sense. I'm going to copy it to an item in the Issue Tracker so that I don't lose it.


Jan 25, 2012 at 10:11 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Mar 26, 2012 at 6:13 PM


FYI - I just wanted to let you know that I'm looking into this now. There are a few quirks to it, as sometimes the closing td is lowercase and sometimes uppercase, but I do think it's going to be a more efficient method. Thanks again for posting it.