Comments on: An Approach to Lazy Loading Custom Elements https://css-tricks.com/an-approach-to-lazy-loading-custom-elements/ Tips, Tricks, and Techniques on using Cascading Style Sheets. Wed, 15 Feb 2023 09:16:41 +0000 hourly 1 https://wordpress.org/?v=6.2.2 By: Frederik Dohr https://css-tricks.com/an-approach-to-lazy-loading-custom-elements/#comment-1802955 Wed, 15 Feb 2023 09:16:41 +0000 https://css-tricks.com/?p=376991#comment-1802955 I’d be interested to see an example of your iframes approach, Michael; care to put it in a CodePen or Gist? (The latter would allow for dedicated discussions.)

I sympathize with the HTML Import mourning, though I go back and forth on what it could or should have been.

]]>
By: Michael Ninin https://css-tricks.com/an-approach-to-lazy-loading-custom-elements/#comment-1802941 Tue, 14 Feb 2023 06:21:27 +0000 https://css-tricks.com/?p=376991#comment-1802941 I am still dreaming of html imports. Think of any landing sections in separate html files. The important thing for me is I want for them to be shown in Sources tab along with others. So fetch is not helpful. So I tried a dedicated custom element with iframes loading separate html files in it, and that element is grabbing their documents contents and move them into our main one. That is solving my issue with showing them in Sources tab. But races are killing me… It works like 15 times out of 16.(

]]>
By: Frederik Dohr https://css-tricks.com/an-approach-to-lazy-loading-custom-elements/#comment-1802939 Mon, 13 Feb 2023 20:27:21 +0000 https://css-tricks.com/?p=376991#comment-1802939 Oh, I hadn’t thought of :defined in this context; that’s an excellent idea and much more elegant, thank you!

I agree that an approach like that elems object can be advantageous in some scenarios (thus the cautionary aside in the introduction). In my case, I specifically didn’t want to rely on bundlers or similar tooling though.

]]>
By: Molly Stewart-Gallus https://css-tricks.com/an-approach-to-lazy-loading-custom-elements/#comment-1802937 Mon, 13 Feb 2023 19:59:18 +0000 https://css-tricks.com/?p=376991#comment-1802937 Why not use :not(:defined) to query for unloaded elements.

I would also use a different sort of autoloader which is more easily WebPackable. Something like

const elems = {
'my-elem': () => import('./my-elem.js')

};
// …

customElements.define(elem, await elemselem. default);`

]]>