Recommendations for session.putClientData() and max size to store?

Vegard S
Kilo Sage

Hi! I was wondering if there's any recommendations and best practices around the use of session.putClientData()?
I'm embedding three widgets into a service portal header menu. And instead of loading them all for each page load using $sp.getWidget, I store each widget in their own session data cache instead.

This is several seconds faster to load. Each widget's data ranges from around 60-100kb or so.

Does anyone think this is a terrible idea? The docs doesn't say anything about the recommended size of the data to put into client data. So I don't want to generate performance issues by doing this.

1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hi @Vegard S ,

We do not have any doc as such which tells the recommended Size.

Here are some best practices for using the session.putClientData() method in ServiceNow:
  • Use the getSession() method
    Use the getSession() method of the scoped GlideSystem API instead of GlideSession.
  • Use GlideSession.getClientData()
    Use the GlideSession.getClientData() method to retrieve data values that were set using putClientData(). 
     
     
     
Some other best practices for client scripts in ServiceNow include:
  • Wrapping code in functions
  • Running only necessary client scripts
  • Avoiding using GlideRecord queries in client side scripts
  • Avoiding using synchronous AJAX methods in client side scripts

View solution in original post

2 REPLIES 2

Community Alums
Not applicable

Hi @Vegard S ,

We do not have any doc as such which tells the recommended Size.

Here are some best practices for using the session.putClientData() method in ServiceNow:
  • Use the getSession() method
    Use the getSession() method of the scoped GlideSystem API instead of GlideSession.
  • Use GlideSession.getClientData()
    Use the GlideSession.getClientData() method to retrieve data values that were set using putClientData(). 
     
     
     
Some other best practices for client scripts in ServiceNow include:
  • Wrapping code in functions
  • Running only necessary client scripts
  • Avoiding using GlideRecord queries in client side scripts
  • Avoiding using synchronous AJAX methods in client side scripts

Vegard S
Kilo Sage

Ok, I'm well within all of this. And it's not a huge amount of data we're talking about. 
I'm gonna let this thread be open for a day or two, just in case anyone has some feedback I should know about 🙂