SPFx and HTML Imports (from Web Components)

Copper Contributor

I've been looking for an alternative to using an <iframe/> in the web part I am working on. The web part ("App Panel") is meant to have replaceable content display depending on how it is configured.  The idea is a sort of 'mini-dashboard' for a line of business (LOB) application, where the replaceable content provides a data point or two and maybe button for a pop-up with some more info.  The name of the app and a direct link to it will be set as properties (displayed top and bottom), but I need some way to get current content for the current user to display in the middle. (see the B section in the illustration)


My original thought was to use an <iframe/> pointing to another page on the site (no CORS needed) that the user would never visit by itself, but getting it to look right would be challenging.  But then I came across the idea of using HTML Imports as an alternative to iframe. This is part of the Web Components spec that is not the web components themselves. The basic concept is to specify a <div> on another page and be able to insert that one into a <div> in my web part at run time.


What I would like to do is create a web part that generates the content I want to display on a new page in the site, and then use the HTML Imports to get that generated <div> and host it in my App Panel web part.  This would essentially de-couple each App Panel from the LOB application that is providing the content, and allow me to add new LOB apps as time goes on without having to add/change the code and re-deploy the App Panel web part itself.


My Google-fu has failed me when attempting to find information about using HTML Imports in the context of the SharePoint Framework.  Does anyone know if this is even possible, and if so how it might be accomplished?


Thanks in advance.

0 Replies