javascripthtmlpolymercustom-elementhtml-imports

Is an event fired when an HTML import finishes loading?


So I am loading a load screen in my app. Then I load my custom elements through HTML imports by making a link element in JavaScript. I need to know when this HTML import has finished loading to display content to the user. Do HTML imports fire an event when the download finishes?


Solution

  • You have onload event.

    <script async>
      function handleLoad(e) {
        console.log('Loaded import: ' + e.target.href);
      }
      function handleError(e) {
        console.log('Error loading import: ' + e.target.href);
      }
    </script>
    
    <link rel="import" href="file.html"
          onload="handleLoad(event)" onerror="handleError(event)">
    

    For more on imports, here you go.