oduwsdl / MementoEmbed

A service that provides archive-aware oEmbed-compatible embeddable surrogates (social cards, thumbnails, etc.) for archived web pages (mementos).
MIT License
15 stars 3 forks source link

Use CustomElements for cards #48

Open ibnesayeed opened 6 years ago

ibnesayeed commented 6 years ago

If these cards are intended to be used in other sites, it might be a good idea to utilize HTML CustomElements for bi-directional style isolation. We are using it in Reconstructive Banner. Here are some other resources that will help you get started with this fairly new HTML standard.

machawk1 commented 6 years ago

Custom Element support appears to be lacking: https://caniuse.com/#feat=custom-elements

Maybe feature detect to serve a Custom Elements version and fallback to the current version until more browsers support them.

ibnesayeed commented 6 years ago

The situation is not as bad because support for draft v1 (as opposed to v0) has landed in Safari as well https://caniuse.com/#feat=custom-elementsv1. Current global reach of browsers that support CustomElements is almost 80%. Partial support is not an issue as we will not be using currently unsupported features anyway. Firefox has it available behind a flag and intends to enable it by default in it v61 release (though it missed its plans to enable it by default in v60). Edge browser is considering it, but that is not as significant.

As far as fallback option is concerned, we can use iframes as a fallback and if we want to reuse the markup, we can perhaps utilize well-supported HTML templates to conditionally clone the content into an iframe or a custom element (I am not too sure about the possibility of this reuse, but just thinking out loud here).

shawnmjones commented 6 years ago

I have 3 main concerns with custom elements:

  1. accessibility - How do screen readers deal with them? You'll note that the card I've created degrades to just a text snippet and a title for the benefit of screen readers.
  2. browser support - this is addressed in the conversation above
  3. archivability - I've actually considered ditching the JavaScript rendering altogether in favor of archive-friendly HTML. One of my goals is that these cards should not hinder the page's archivability. How well do the custom elements function in this environment?

I think it's a great idea. I'd just like to see it mature some more.

ibnesayeed commented 6 years ago

Those are legitimate concerns and I think we can check all those boxes with growing confidence going forward.

shawnmjones commented 6 years ago

I spoke with @phonedude about this issue today and the biggest concern at the moment is browser support.

2018-07-10_11-47-37

I am keeping this issue open so that development can begin on it once Custom Elements is more widely supported by browsers.

ibnesayeed commented 6 years ago

the biggest concern at the moment is browser support.

As I noted before, there is actually a pretty good native browser support already (as far as the market share is concerned). For remaining browsers like Firefox and Edge, there are polyfills available. Firefox is about to make it generally available (not behind a flag) soon. Look at the browser support matrix on the official site of Web Components.

shawnmjones commented 6 years ago

I may make this an option for the user, depending on the priority of other issues. A web page author should be aware of their audience and may not care about supporting certain browsers (like Edge).

ibnesayeed commented 6 years ago

Firefox 63, publicly released last month, now supports custom elements by default, hence a relevant issue in IPWB https://github.com/oduwsdl/ipwb/issues/433 is now closed.

shawnmjones commented 6 years ago

Thank you for letting me know. I'll look into a CustomElements implementation soon.