4

Looking for briljant ideas...

I have a 100% Front-End driven UX only pulling in content from SharePoint
Nothing fancy, the usual stuff: News Carousel & Summary, My Tasks , Birthday list etc.
All the 100% Front-End stuff we are now supposed to do with SPFx

A large part is about user-context (Department, Office etc), so I need all his/her properties FAST
Before I can fire other REST requests for more content.

I can live with 150 milliseconds, but regularly taking a whole second is ludicrous

(I did a replay-XHR manually so these are fairly random response times)

I can't do much about SharePoint (ASPX) content being slow

I can however cache this content myself and proces slow incoming userdata later

Caching UserProfileProperties ?

LocalStorage

  • easy to develop

  • tied to Browser

use my own HTTPS server

  • Less easy to develop (but done it in non-Microsoft days.. 40% of this code ran on WordPress)

  • feels a bit like the first step to building SharePoint myself
    next question then would be:

Why store content IN SharePoint? As SPO Content requests are as whimsical in performance


Any other suggestions?

iSPEED iREST

  • Just a comment as it doesn't necessarily pertain to my answer, "All the 100% Front-End stuff we are now supposed to do with SPFx", there is no one forcing you to use SPFx for 100% client applications. You can still use whatever methodology you want. Just because it is the new hotness, doesn't mean the existing toolsets are junk. – Eric Alexander Jan 31 '17 at 21:49
  • This is an all Front-End environment coming from WordPress (where it performs fine) When Microsoft touted the future being Front-End I only looked (because I knew React) at SPFx (nearly a year ago) ditched it (because it requires very very skilled programmers en our approach allows anyone with just HTML5 skills to built an Intranet) and now only use SPFx to get our library into the page. SPFx is great, standard SP WPs are decent, endpoints suck. – Danny '365CSI' Engelman Feb 1 '17 at 8:31
2

You can also Batch REST API calls using SPHttpClientBatch class. Will save you some round trips. After that you can use the local/session storage as suggested by Eric.

What you need to do:

1) Add the below import statement

import { SPHttpClient, ISPHttpClientBatchOptions, ISPHttpClientBatchCreationOptions, SPHttpClientBatchConfigurations, SPHttpClientResponse, SPHttpClientBatch } from '@microsoft/sp-http';

2) After that in your method, you need to use it as follows:

const spBatchCreationOpts: ISPHttpClientBatchCreationOptions = { webUrl: this.context.pageContext.web.absoluteUrl };

const spBatch: SPHttpClientBatch = this.context.spHttpClient.beginBatch(spBatchCreationOpts);

// Queue first call to get current user properties
const getMyProperties: Promise<SPHttpClientResponse> = spBatch.get(`${this.context.pageContext.web.absoluteUrl}/_api/SP.UserProfiles.PeopleManager/GetMyProperties`, SPHttpClientBatch.configurations.v1);

// Queue second call to get another user's properties
const getAnotherUsersProperties: Promise<SPHttpClientResponse> = spBatch.get(`${this.context.pageContext.web.absoluteUrl}/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='i:0%23.f|membership|user@tenantname.onmicrosoft.com'`, SPHttpClientBatch.configurations.v1);


spBatch.execute().then(() => {

      getMyProperties.then((response: SPHttpClientResponse) => {
        response.json().then((props: any) => {
          console.log(props); 
        });
      });

      getAnotherUsersProperties.then((response: SPHttpClientResponse) => {
        response.json().then((props: any) => {
          console.log(props);
        });
      });      
});

Reference - SPHttpClient class

Excellent blog post by Vardhaman - Batch REST requests in SPFx

  • The FIRST call is slow. Please explain how to make a FASTER Batch call: .......... ..... GetUserProperties AND GetTaskofThisUserThatNeedToBeCompletedToday – Danny '365CSI' Engelman Feb 1 '17 at 9:00
  • Using batching there is only going to be one call. It looks slow because the payload could be bigger in your requests. do have a look at this image - i.stack.imgur.com/QHDN8.png , it shows the $batch endpoint only instead of multiple ajax requests. Also, ` GetUserProperties` is optimized to run with the minimal metadata mode,so its already optimized. Can you elaborate more on what exactly is slow ? Also i dont think faster batch call is possible since there is only going to be one call. – Gautam Sheth Feb 1 '17 at 17:16
1

Local storage would be the best option I suppose, first load initially, or first load on a new browser would be slow but pick up after that, but that is the norm for most sites (when talking about static assets anyway). Make the expensive calls once, merge them up into your own object and hand it off to store.js to manage.

Passing it off to a provider hosted app won't make much of a difference. You still have to get the SharePoint user context to then pass off to your service, so you're still waiting for SharePoint.

I know you've harped on this speed issue a couple times, but there are fundamental differences in WordPress and SharePoint. Totally different architectures and designs, stand alone versus hosted and shared. It's like wondering why your Fiat has a terrible 0-60 versus the Porsche, they're just cars right?

  • 1
    I'd add one more comment (since your answer is pretty much what I would suggest). See if you can register the call to get the profile data as soon as you can in the page lifecycle. Ie, don't make the call immediately before you need the property. – PatMill_MSFT Feb 1 '17 at 1:27
  • And/or consolidate the calls, fewer fatter requests than many small potentially (depending on what your code is doing) – Eric Alexander Feb 1 '17 at 1:41
  • I actually drive my mums 1969 Fiat-500 sometimes.. better babe magnet than a Porsche (But I like women with brains over bimbos) – Danny '365CSI' Engelman Feb 1 '17 at 8:41
  • Get code in early... Hmmm... UserCustomAction! .. oops.. that was killed in Modern Experiences after it did work in Drop 1 – Danny '365CSI' Engelman Feb 1 '17 at 9:04
  • LOL.. moved the code to the very first line in a UAC ScriptLink: i.imgur.com/BPvlETy.jpg [Screenshot now showing a load time of TWO SECONDS] – Danny '365CSI' Engelman Feb 1 '17 at 9:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.