TL;DR: We plan to support iframes as soon as we are happy with an embed design that maintains a static aspect ratio.
This issue details our difficulty using iframes for our particular embed needs, and why we're punting on them for now. It's not impossible, just enough of a lift to move out of MVP.
A common request and a strong internal desire is for our embeds to be delivered via iframes. This has significant advantages: the iframe is a silo within which our JS/CSS are safe from the parent page (and vice versa), and as a single HTML tag it's generally portable:
Wouldn't that be nice. Unfortunately, it's not responsive at all. This is usually solved with a little HTML wrapping and some CSS, so you end up with something like this:
<style>…</style>
<div class="iframe-wrapper><iframe src></div>
A little gross, but at least it doesn't require any JS on the parent page. Unfortunately, it only works if the embed maintains a static aspect ratio, like a video. For those with aspect ratios that could change while the embed is being used or resized, like ours, you have to whip out the JS:
<iframe src>
<script src></script>
What would this script have to do?
- Initialize responsiveness by injecting the necessary HTML/CSS for the above-mentioned method
- Maintain aspect ratio when a parent page resize/reflow causes the iframe to resize
- Listen to the iframe's child page for resize-triggering events and apply them to the iframe
That last one is the doozy and why Pym exists.
– begin aspect ratio tangent –
It's useful to ask: what causes us to have a variable aspect ratio? Why can't we calculate the ideal aspect ratio for a given resource when generating its embed code and force ourselves to keep it? Here's what causes aspect ratio changes:
- Notes: Our current page embed design can cause notes to pop out of the bounds of the page embed.
- Page navigation: Different pages within a document can have different aspect ratios. Embedding a single page can initialize at that page's aspect ratio, but if the reader navigates to a new page with a different ratio, the embed has to adjust.
- Interface chrome: While images can scale almost infinitely, interface chrome has reasonable usability bounds. So we have a static 40px-tall menu bar atop a page that's 400px wide and 760px tall. Total embed
width:height is 400px:800px for an aspect ratio for 1:2. Now shrink the page to 200px wide and 380px tall; total embed is 200px:420px for an aspect ratio of 1:2.1.
There are design compromises for each of these problems; we just have to decide if they're worthwhile.
– end aspect ratio tangent –
### So what are we going to do?
We'll start with the progressive enhancement model used by Twitter and others, where the initial embed code is effectively a noscript replacement plus some JS:
<div class="DC-embed-stub>
<p><a href="…">Minutes from the 12/2014 meeting</a></p>
<img src>
</div>
<script src></script>
The script then parses the faux-noscript and replaces it with the real direct-embed markup.
When will we add iframes?
- When we design an interface that promises a static aspect ratio, or
- When we can do all of the following:
- Fork or enhance Pym to fit our progressive enhancement model (it currently appends to a div instead of replacing contents) and to not mind being embedded multiple times per page
- Provide a stable message-passing API atop Pym between parent and child
- Provide an initial iframe state that also acts as a
noscript, or basically a non-responsive and potentially mis-aspect-ratioed representation of the embed, but which we are satisfied with as the worst-case fallback
TL;DR: We plan to support iframes as soon as we are happy with an embed design that maintains a static aspect ratio.
This issue details our difficulty using iframes for our particular embed needs, and why we're punting on them for now. It's not impossible, just enough of a lift to move out of MVP.
A common request and a strong internal desire is for our embeds to be delivered via iframes. This has significant advantages: the iframe is a silo within which our JS/CSS are safe from the parent page (and vice versa), and as a single HTML tag it's generally portable:
Wouldn't that be nice. Unfortunately, it's not responsive at all. This is usually solved with a little HTML wrapping and some CSS, so you end up with something like this:
A little gross, but at least it doesn't require any JS on the parent page. Unfortunately, it only works if the embed maintains a static aspect ratio, like a video. For those with aspect ratios that could change while the embed is being used or resized, like ours, you have to whip out the JS:
What would this script have to do?
That last one is the doozy and why Pym exists.
– begin aspect ratio tangent –
It's useful to ask: what causes us to have a variable aspect ratio? Why can't we calculate the ideal aspect ratio for a given resource when generating its embed code and force ourselves to keep it? Here's what causes aspect ratio changes:
width:heightis400px:800pxfor an aspect ratio for1:2. Now shrink the page to 200px wide and 380px tall; total embed is200px:420pxfor an aspect ratio of1:2.1.There are design compromises for each of these problems; we just have to decide if they're worthwhile.
– end aspect ratio tangent –
### So what are we going to do?
We'll start with the progressive enhancement model used by Twitter and others, where the initial embed code is effectively a
noscriptreplacement plus some JS:The script then parses the faux-noscript and replaces it with the real direct-embed markup.
When will we add iframes?
noscript, or basically a non-responsive and potentially mis-aspect-ratioed representation of the embed, but which we are satisfied with as the worst-case fallback