5

We have 2 list view buttons on one page and each references the same js file (e.g., hosted on googleapis.com) having line of code:

{!REQUIRESCRIPT("https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.js")}

Every time list view page that has these 2 buttons is loaded it downloads this js file 2 times (for 2 buttons). For the 2nd button it doesn't use browser cache (file downloaded for 1st button), because SF adds different tokens every time external resource is requested using REQUIRESCRIPT function. E.g.,

-for the 1st button: https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.js?_=1437493934758&callback=jsonp36

-for the 2nd button: https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.js?_=1437493937970&callback=jsonp44

In case of having 5 such buttons when every button references e.g. 3 files and every file takes e.g. 1 sec to load (by the way, it can be hosting other than googleapis.com) this will take 5*3*1=15 sec to load for all buttons. It can be an issue, since user sees that page is loaded, buttons are available but every single button doesn't work until it loaded all js files referenced by REQUIRESCRIPT function (as I've observed SF loads them one by in order buttons are placed on page).

Is there a way to force SF using cache or get rid of these tokens when using REQUIRESCRIPT function, so js from cache could be used for the 2nd button in my first example?

Thanks

2

The best solution for an issue like this is to use a Salesforce Static Resource to host your JavaScript library. Hopefully this will solve your caching issues.

See how tehnrd does it here.

  • 2
    Referencing static resources in list view buttons using REQUIRESCRIPT doesn't work after "Serve Static Resources from Visualforce domain" critical update is activated. For details, please, see this known issue that won't be fixed success.salesforce.com/issues_view?id=a1p300000008XRLAA2 – Victor Jul 22 '15 at 9:53
1

This issue should be addressed with following change in Winter 16 release:

REQUIRESCRIPT No Longer Executes JavaScript On Page Load

We’ve changed the way custom JavaScript buttons and links work when they use REQUIRESCRIPT. The REQUIRESCRIPT resources aren’t included in the page until the user clicks the custom JavaScript button or link.

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.