<script>
  function supportsCustomEvents() {
    try {
      new CustomEvent('test');
      return true;
    } catch (err) {
      return false;
    }
  }

  function supportsPromises() {
    return typeof Promise !== 'undefined' && Promise.toString().indexOf('[native code]') !== -1;
  }

  function browserSupportsAllFeatures() {
    return (window.fetch && window.IntersectionObserver && supportsCustomEvents() && supportsPromises());
  }

  function loadScript(src) {
    const js = document.createElement('script');

    js.src = src;
    document.head.appendChild(js);
  }

  if (!browserSupportsAllFeatures()) {
    loadScript('{{ getJSBundle 'polyfills' }}');
  }
</script>
