I am new with poly filling and I have been looking at some articles about it, such as this simple one here. But with sharepoint not being able to load 3rd party scripts, can someone walk me through what the best way is to do so?



I assume by not able to load 3rd party scripts, you mean that you can't reference scripts outside of your site collection in user custom actions?

If so, the easiest solution would be to put a script in your site collection, load it as a custom action, and have that script add a script tag to load the external resource. Taking the example that article gives, you can add a script with:

var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://cdn.polyfill.io/v2/polyfill.min.js';

// added this, very important!
script.async = false;


Put this script in your Style Library, and load it via a custom action. Make sure any other scripts you have that want to use Promise are loaded after this script (i.e. higher sequence number, or JSLink). And that's it, you now have a working pollyfill.


Normally, browsers that support the async attribute (all modern browsers) for scripts will load and execute dynamically added scripts (i.e. added through DOM manipulation or document.write) as quickly as possible, which means the second script could be executed before the first has been loaded. Browsers that don't support the async attribute will always load and execute scripts synchronously, whether dynamically added or not.

But, with this flag set to false, the dynamic script will pause further rendering until it has executed completely, which means the second script can count on the first script being ready for use from the start. And since browsers that don't support async are synchronous by default, this should work for them too (with some caveats).

The caveats are that due to bugs or partial implementation of async, the order of execution of these scripts is not guaranteed in IE 4-9 or Safari 5.0 (see async attribute for external scripts), but it should work reliably in all reasonably modern browsers.

| improve this answer | |
  • I tried adding a script in but when traced, it seems like it doesn't execute that poly before the rest of the code. How can I resolve that? – Isa Feb 13 '19 at 22:24
  • Any code that depends on the poly needs to be in a separate JavaScript file that is loaded/executed later than the above code. – Joe McShea Feb 14 '19 at 20:08

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.