<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Max Rafferty on Medium]]></title>
        <description><![CDATA[Stories by Max Rafferty on Medium]]></description>
        <link>https://medium.com/@max-rafferty?source=rss-ca1aae1643df------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*f8KVlzzKlJ9QIamsjskX3w.jpeg</url>
            <title>Stories by Max Rafferty on Medium</title>
            <link>https://medium.com/@max-rafferty?source=rss-ca1aae1643df------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 21:15:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@max-rafferty/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Iframe Performance Part 2: The Good News]]></title>
            <link>https://medium.com/slices-of-bread/iframe-performance-part-2-the-good-news-26eb53cea429?source=rss-ca1aae1643df------2</link>
            <guid isPermaLink="false">https://medium.com/p/26eb53cea429</guid>
            <category><![CDATA[iframe]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[js]]></category>
            <dc:creator><![CDATA[Max Rafferty]]></dc:creator>
            <pubDate>Thu, 21 Jan 2021 21:18:21 GMT</pubDate>
            <atom:updated>2021-01-21T21:21:49.233Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ScdrZz5xucPKcpf-FaKMxw.jpeg" /></figure><p>This article is the third in a series about working with iFrames. The first, <a href="https://medium.com/slices-of-bread/iframe-a-love-story-3dbe4e519b86">iframe: A Love Story</a>, describes a brief history of the iframe, and how and why we need them at Bread. The second, <a href="https://medium.com/slices-of-bread/iframe-performance-part-1-the-bad-news-2bd945ce1e6">part one of this article</a>, describes and analyzes the performance issues that plague iFrames.</p><p>•✧─────────────✧¸.•´*¨`*•✿•*`¨*`•.¸✧─────────────✧•</p><h3>Alternative Load Methods to the Rescue</h3><p>One of the most powerful tools at our disposal when dealing with frames is the ability to utilize the src and srcdoc attributes to directly inject our markup rather than letting the iFrame handle the network portions of the operation. There are other techniques, like dynamically loading the elements after page ready, that can give us further flexibility, but we will focus on these new load methods as they are easy to implement across the board, and have a dramatic effect on load times. Other techniques have more caveats, but should be explored situationally.</p><h3>Scenario 1: Data URI pages</h3><p>Much like images, iFrames also have a src element and can have their content pages be base64 encoded as a Data URI. This takes some finagling, especially for larger pages with more special characters, but eventually you will end up with a <em>very beautiful</em> frame like the following:</p><pre>&lt;iframe src=&quot;data:text/html;base64,PCFET0NUWVBFIGh0bWw+PGh0bWw+PGhlYWQ+DQogIDxtZXRhIGh0dHAtZXF1aXY94oCdY29udGVudC10eXBl4oCdIGNvbnRlbnQ94oCddGV4dC9odG1sOyBjaGFyc2V0PVVURi04Ij48dGl0bGU+aUZyYW1lIFBlcmZvcm1hbmNlPC90aXRsZT4NCjxib2R5Pg0KICA8YSB0aXRsZT0iTWljaGFsIEtsYWpiYW4sIENDIEJZLVNBIDQuMCAmbHQ7aHR0cHM6Ly9jcmVhdGl2ZWNvbW1vbnMub3JnL2xpY2Vuc2VzL2J5LXNhLzQuMCZndDssIHZpYSBXaWtpbWVkaWEgQ29tbW9ucyIgaHJlZj0iaHR0cHM6Ly9jb21tb25zLndpa2ltZWRpYS5vcmcvd2lraS9GaWxlOiUyMkV2ZXJ5dGhpbmdfaXNfR29pbmdfdG9fYmVfQWxyaWdodCUyMl9hcnR3b3JrLF9DaHJpc3RjaHVyY2hfQXJ0X0dhbGxlcnksX0NocmlzdGNodXJjaCxfTmV3X1plYWxhbmQuanBnIj48aW1nIGFsdD0iJnF1b3Q7RXZlcnl0aGluZyBpcyBHb2luZyB0byBiZSBBbHJpZ2h0JnF1b3Q7IGFydHdvcmssIENocmlzdGNodXJjaCBBcnQgR2FsbGVyeSwgQ2hyaXN0Y2h1cmNoLCBOZXcgWmVhbGFuZCIgc3JjPSJodHRwczovL3VwbG9hZC53aWtpbWVkaWEub3JnL3dpa2lwZWRpYS9jb21tb25zL3RodW1iLzIvMjEvJTIyRXZlcnl0aGluZ19pc19Hb2luZ190b19iZV9BbHJpZ2h0JTIyX2FydHdvcmslMkNfQ2hyaXN0Y2h1cmNoX0FydF9HYWxsZXJ5JTJDX0NocmlzdGNodXJjaCUyQ19OZXdfWmVhbGFuZC5qcGcvNDA5NnB4LSUyMkV2ZXJ5dGhpbmdfaXNfR29pbmdfdG9fYmVfQWxyaWdodCUyMl9hcnR3b3JrJTJDX0NocmlzdGNodXJjaF9BcnRfR2FsbGVyeSUyQ19DaHJpc3RjaHVyY2glMkNfTmV3X1plYWxhbmQuanBnIj48L2E+DQogIDxzY3JpcHQgdHlwZT0idGV4dC9qYXZhc2NyaXB0Ij4vLzwhW0NEQVRBWw0KICAgIHdpbmRvdy5hZGRFdmVudExpc3RlbmVyKCdsb2FkJywgKGV2ZW50KSA9PiB7DQogICAgICB3aW5kb3cucGFyZW50LnBvc3RNZXNzYWdlKCJmcmFtZSBsb2FkZWQiLCAiKiIpOw0KICAgIH0pOw0KLy9dXT48L3NjcmlwdD4NCjwvYm9keT48L2h0bWw+&quot;&gt;The “iframe” tag is not supported by your browser.&lt;/iframe&gt;</pre><p>The theory here is to remove the network element entirely. If that is a part of the problem, then we should see notable improvement with this approach.</p><p><a href="https://jsfiddle.net/MaxPRafferty/az9mk7o4/">Set up the same way</a> as our previous experiment, our first test shows promising results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*6ERQWyxnRKXHXzKZ6Js2fw.png" /></figure><p>While an astute reader will note that “of course removing the network call speeds things up”, there is no reason that this isn’t accomplishable in nearly every situation. These strings can be included in the main JS or HTML payloads without much difficulty. In any event, the result is dramatic. With the exception of our interesting outlier, performance is improved 4x consistently with this technique.</p><h3>Scenario 2: srcdoc</h3><p>This approach is <a href="https://jsfiddle.net/MaxPRafferty/8x7c4yaL/">nearly identical to the last</a>, however it uses raw HTML in the srcdoc element rather than an encoded document in the src. The srcdoc element is very interesting. It was designed to provide an “override” for the src element to increase browser support, which is no longer an issue, but it is still useful if we want to manually populate our frame with somewhat more readable markup. This is a little easier to put together than the prior example, though you’ll frequently need to escape quotes:</p><pre>&lt;iframe srcdoc=’&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;</pre><pre>&lt;meta http-equiv=”content-type” content=”text/html; charset=UTF-8&quot;&gt;&lt;title&gt;iFrame Performance&lt;/title&gt;</pre><pre>&lt;body&gt;</pre><pre>&lt;a title=”Michal Klajban, CC BY-SA 4.0 &amp;lt;https://creativecommons.org/licenses/by-sa/4.0&amp;gt;, via Wikimedia Commons” href=”https://commons.wikimedia.org/wiki/File:%22Everything_is_Going_to_be_Alright%22_artwork,_Christchurch_Art_Gallery,_Christchurch,_New_Zealand.jpg&quot;&gt;&lt;img alt=””&amp;quot;Everything is Going to be Alright&amp;quot; artwork, Christchurch Art Gallery, Christchurch, New Zealand” src=”https://upload.wikimedia.org/wikipedia/commons/thumb/2/21/%22Everything_is_Going_to_be_Alright%22_artwork%2C_Christchurch_Art_Gallery%2C_Christchurch%2C_New_Zealand.jpg/4096px-%22Everything_is_Going_to_be_Alright%22_artwork%2C_Christchurch_Art_Gallery%2C_Christchurch%2C_New_Zealand.jpg&quot;&gt;&lt;/a&gt;</pre><pre>&lt;script type=”text/javascript”&gt;//&lt;![CDATA[</pre><pre>window.addEventListener(‘load’, (event) =&gt; {</pre><pre>window.parent.postMessage(“frame loaded”, “*”);</pre><pre>});</pre><pre>//]]&gt;&lt;/script&gt;&lt;/body&gt;&lt;/html&gt;’&gt;The “iframe” tag is not supported by your browser.&lt;/iframe&gt;</pre><p>This one may look a little strange given that it is a string of escaped HTML inside of another HTML tag. It is not quite as concise as our prior example, but some may consider it easier to write by hand. Note that we needn’t include a complete document as we have here; fragments are acceptable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*_Cf9uNX-VF72sRRTRJeTXw.png" /></figure><p>While not quite as effective as the encoded src, which is mildly surprising given that the data URI must be parsed and decoded twice, this is still better than the control. Performance here is closer to 2x, but if for whatever reason base64 encoding your markup is unappealing, this technique is still viable. This could be the case if you are generating your markup on the fly or downloading it separately unencoded.</p><p>These results are very encouraging. At face value, it appears that as one might expect, removing the network does significantly increase iFrame performance. By combining these with lazy loading, as well as other more common tricks to reduce the <em>apparent</em> load time, we can get close to the appearance of near-instantaneous loading of iFrames.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=26eb53cea429" width="1" height="1" alt=""><hr><p><a href="https://medium.com/slices-of-bread/iframe-performance-part-2-the-good-news-26eb53cea429">Iframe Performance Part 2: The Good News</a> was originally published in <a href="https://medium.com/slices-of-bread">Slices of Bread</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[iFrame Performance: Part 1, The Bad News]]></title>
            <link>https://medium.com/slices-of-bread/iframe-performance-part-1-the-bad-news-2bd945ce1e6?source=rss-ca1aae1643df------2</link>
            <guid isPermaLink="false">https://medium.com/p/2bd945ce1e6</guid>
            <category><![CDATA[iframe]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[performance]]></category>
            <dc:creator><![CDATA[Max Rafferty]]></dc:creator>
            <pubDate>Fri, 04 Dec 2020 23:45:42 GMT</pubDate>
            <atom:updated>2021-01-21T20:47:06.461Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vZyeMaSMneJLXAZlmc4J-w.jpeg" /></figure><p>This article is the second in a series about working with iFrames. The first, <a href="https://medium.com/slices-of-bread/iframe-a-love-story-3dbe4e519b86">iframe: A Love Story</a>, describes a brief history of the iframe, and how and why we need them at Bread.</p><p>•✧─────────────✧¸.•´*¨`*•✿•*`¨*`•.¸✧─────────────✧•</p><h3>It’s just HTML, who cares about performance?</h3><p>We previously discussed why our team over here at Bread has no alternative to the iFrame element and all of its quirks. One of the most important of these quirks is ensuring that our frames, and the pages and scripts within them are responsive and available, and crucially, do not degrade the experience of users on the sites of our merchant partners: in short, performance. In modern browsers, we rarely concern ourselves with the performance of HTML, in favor of the typically much more fruitful optimizations to be made in Javascript. As with so many other things, the iFrame is once again the exception. iFrames have their own network concerns, separate document context, and their own set of lifecycle moments, not to mention them being quite variable from browser to browser. Taken all together, there is not a lot of good news on this front: iFrame performance is, generally speaking, terrible.</p><h3>Alright, how bad is it?</h3><p>Pretty bad.</p><p>Consider the following two control examples we will be using:</p><ol><li><a href="https://jsfiddle.net/MaxPRafferty/bqumr2w4/5/">Control 1</a>: Large Image (~8mb), Ten smaller images (~1mb)</li><li><a href="https://jsfiddle.net/MaxPRafferty/8nuay5Lw/61/">Control 2</a>: Large Image (~8mb), Ten iFrames each containing one image (~1mb)</li></ol><p>These will represent our practical “best” and “worst” case scenarios, the former being content without iFrames, the latter being iFrames we have not attempted to optimize at all. We’ve set up these scenarios in the following way: The large image gives us something to “race” the iFrames against, both from a strict timing perspective and visually, as as with many UX optimizations, we’ll need to be ok here if we can only improve the perceived performance, rather than the actual underlying loads and events. We’ve written a tiny timer script which will be the only additional code in this document, to keep things as light as possible. We’ve opted not to use the lovely console.time here because in part two we’ll be automating these tests for conveniently repeating the experiment in multiple browsers, which will require us to be able to read the time values. For the iFrame contents, we’ll use this simple HTML:</p><pre>&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;<br>  &lt;meta http-equiv=”content-type” content=”text/html; charset=UTF-8&quot;&gt;&lt;title&gt;iFrame Performance&lt;/title&gt;<br>&lt;body&gt;<br>  &lt;a title=”Michal Klajban, CC BY-SA 4.0 &amp;lt;https://creativecommons.org/licenses/by-sa/4.0&amp;gt;, via Wikimedia Commons” href=”https://commons.wikimedia.org/wiki/File:%22Everything_is_Going_to_be_Alright%22_artwork,_Christchurch_Art_Gallery,_Christchurch,_New_Zealand.jpg&quot;&gt;&lt;img alt=”&amp;quot;Everything is Going to be Alright&amp;quot; artwork, Christchurch Art Gallery, Christchurch, New Zealand” src=”https://upload.wikimedia.org/wikipedia/commons/thumb/2/21/%22Everything_is_Going_to_be_Alright%22_artwork%2C_Christchurch_Art_Gallery%2C_Christchurch%2C_New_Zealand.jpg/4096px-%22Everything_is_Going_to_be_Alright%22_artwork%2C_Christchurch_Art_Gallery%2C_Christchurch%2C_New_Zealand.jpg&quot;&gt;&lt;/a&gt;<br>  &lt;script type=”text/javascript”&gt;//&lt;![CDATA[<br>    window.addEventListener(‘load’, (event) =&gt; {<br>      window.parent.postMessage(“frame loaded”, “*”);<br>    });<br>//]]&gt;&lt;/script&gt;<br>&lt;/body&gt;&lt;/html&gt;</pre><p>I’ll maintain a copy of this on an <a href="https://jsfiddle.net/MaxPRafferty/Lpgj3bt5/">additional JSFiddle</a>, though note that these numbers will not be in a CORS situation, where performance is further degraded. For our control numbers, same-site will be fine to illustrate our challenges.</p><h3>The Damage</h3><p><a href="https://sheetsu.com/tables/39820ed9f8">https://sheetsu.com/tables/39820ed9f8</a></p><p>The numbers in the image averages are the most striking here — the mere presence of the frames on the page increases the load time of the other content on the page by 4x. Mind, this is with ten frames — that said, the presence of even one adds between 300ms and 600ms to the time it takes the image to load on the page, and that’s with a reduction of page size by almost 1mb — clearly the network is not the culprit here. For further confirmation, the child page takes ~75ms to load when viewed directly, indicating that neither network <em>nor</em> render time is, at least directly, the cause either. If we enable our local cache, the problem becomes even more clear — the images appear near instantaneously, but the frame load time remains largely unaffected. We can see that the number of frames on a page has a direct and linear relationship with the loading of all elements on the page:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tlBDnakfa-HfZadz" /></figure><p>Note in both of these datasets the presence of the occasional “blip” outliers where the image loads in “normal” time. I’m not going to talk any more about that, but its certainly interesting!</p><h3>Analysis and Solutions</h3><p>Based on these control numbers, we’re going to need to try to see what about a frame adds a static ~600ms. We know iFrames are going to have two, or possibly three inherent delays to the loading of the page — they can’t begin until they are reached in the DOM, they may have a network request, and they must create a new document context and load the DOM into it. Fortunately, for all their ambiguity, iFrames are very configurable. We can control all three of these delays in a variety of ways.</p><ol><li>The DOM. We most frequently encounter issues here with scripts — HTML loads synchronously line by line, downloading resources in the order in which they are encountered before the first paint. Scripts desiring to not block the visual page from loading are commonly placed at the end of the body, so as not to block rendering. Alternatively, they can be loaded dynamically after first page load, or be given async attributes that affect their loading. All of these are options are available for iFrames as well.</li><li>The network. Caching takes care of the majority of issues here, but we have a few options to play with. iFrames provide the srcdoc attribute for manually loading a document, which provides a first vehicle for bypassing the network, as well as for manually GETting and loading the doc. The src attribute can also be used to load an inline document, encoded in the same way as an inline image source.</li><li>The document. This is the area in which we have the least control. A frame loaded without a source defaults to the page about:blank. We may be able to manipulate this default with a combination of the above techniques to shorten the time it takes to mount the page. That said, any solutions here will be highly susceptible to browser to browser variation.</li></ol><p>As alluded to in the third bullet, there is an unfortunate fourth aspect that can affect these load times: the browser. As a result of their many quirks, each browser handles iFrames differently. This is particularly true for cross-origin (CORS) frames, where security concerns are increasingly causing vendors to take varied approaches to locking down any CORS activity, and frequently without much fanfare in release notes. Quirky. We have very little ability to control for this, though we can note when we see aberrant behavior.</p><p>All of this taken together calls for an experiment! We have control numbers, we have possible solutions. In part two of this article, we will set up a series of experiments similar to our second control, utilizing a page containing ten iFrames and the techniques described above. We can then hopefully understand the nature of what is happening in those extra 600ms per frame, and show us how to best speed up pages when we must use iFrames.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2bd945ce1e6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/slices-of-bread/iframe-performance-part-1-the-bad-news-2bd945ce1e6">iFrame Performance: Part 1, The Bad News</a> was originally published in <a href="https://medium.com/slices-of-bread">Slices of Bread</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[iFrame — A love story]]></title>
            <link>https://medium.com/slices-of-bread/iframe-a-love-story-3dbe4e519b86?source=rss-ca1aae1643df------2</link>
            <guid isPermaLink="false">https://medium.com/p/3dbe4e519b86</guid>
            <category><![CDATA[web]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[iframe]]></category>
            <category><![CDATA[dev]]></category>
            <dc:creator><![CDATA[Max Rafferty]]></dc:creator>
            <pubDate>Mon, 13 Apr 2020 04:36:31 GMT</pubDate>
            <atom:updated>2020-12-07T18:43:52.047Z</atom:updated>
            <content:encoded><![CDATA[<h3>iFrame — A love story</h3><figure><img alt="John Lee / Bread Finance © (All Rights Reserved)" src="https://cdn-images-1.medium.com/max/1024/1*Om-IKBYLRGAp3dk7eg-fdg.jpeg" /></figure><p>This article is the first in a series about working with iFrames.</p><p>Our wonderful team at <a href="https://getbread.com/">Bread Finance</a> has built a robust pay-over-time payments platform over the last six years, and our checkout integrations are powered at their core by the inline frame (iFrame) element. Bread’s flexible, convenient, and whitelableable solutions depend on the iFrame to provide security and control, but the iFrame’s many quirks have given many opportunities for the team to develop an expertise around working with them. While modern tooling like the open source <a href="https://github.com/krakenjs/zoid">Zoid</a> suite from our friends over at PayPal can ease these challenges, our complex and nuanced needs require absolute control of the embedded frames we have built our application upon. I encourage readers to explore the series that dives into how many iFrame challenges have been <a href="https://medium.com/@bluepnume/introducing-paypals-open-source-cross-domain-javascript-suite-95f991b2731d">abstracted away</a>, but if this leaves you wondering about the technical nitty-gritty, join us as we take a look at how iFrames are wrangled at Bread.</p><p>•✧─────────────✧¸.•´*¨`*•✿•*`¨*`•.¸✧─────────────✧•</p><p>To kick things off, we need to answer a few fundamental questions: what makes iFrames so unique (and weird, and dangerous!), and given all that, why would we choose to hitch our train to them as a fundamental part of our technology? To really understand what is going on, we’ll need to dive into a little bit of the history of the element and its original intended uses. We’ll then look at how the landscape of embeddable applications set into the options we have today, and what the advantages and disadvantages of each of these approaches is. Ultimately we’ll want to answer why the iFrame is the safest and best answer to Bread’s unique set of requirements.</p><p><strong>So then, what’s up with them there frames?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VJTm4uTlKcnIBWAJ9xnAMQ.jpeg" /><figcaption>Markus Trienke / CC BY-SA (<a href="https://creativecommons.org/licenses/by-sa/2.0">https://creativecommons.org/licenses/by-sa/2.0</a>)</figcaption></figure><p>The humble inline frame. We have asked a lot of this element that quietly snuck onto the stage in 1994; At that time its only purpose was to play cleanup for its sibling elements, the FrameSet and Object tags. At this time, the primary use case for frames was to hold common page elements, such as navigation, in order to reduce the usage of precious bandwidth over dial-up. IFrame saw some use in guestbooks and other small applications where we wanted to target the frame for navigation purposes, but overall they played third fiddle. It should be noted that at this time even the specification is not especially clear about when one frame should be chosen over another, citing <a href="https://www.w3.org/TR/html4/struct/objects.html#embedded-documents">“different content models”</a>. The early web was a different time, and for context the iFrame predates even a full implementation of CSS (2000’s IE5 for Mac, go figure!) We’ll want to keep these humble roots in mind when we examine the iFrame, and its quirks, in a modern light.</p><p>Things got interesting once the ad-men got their hands on our humble frame. Enter the late 90s: the dot com bubble was inflating, as was the desire for a more robust cross-domain application controls. So too was the iFrame specification inflating, with the HTML5 iFrame section exploding from from <a href="https://www.w3.org/TR/html4/present/frames.html#h-16.5">six sentences</a> to <a href="https://www.w3.org/TR/html52/semantics-embedded-content.html#the-iframe-element">eleven and a half pages</a>. There were no more clarifying articles on when to use Object and iFrame, iFrame was for documents that needed cross-domain communication with the host page, and Object was for applets, specifically Flash (and what about that fancy new embed tag?). Sibling elements Frame and FrameSet went the way of the Marquee, and so iFrame had to carry their burdens as well. The rising ubiquity of advertising and user tracking guaranteed a continued need for cross-domain scripting. This culminated in the mid-aught appearance of the postMessage standard and cemented the iFrame as a key tool in the web-dev’s kit. A humble element no longer.</p><p><strong>Why choose to use iFrame?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3rj4R6eDuqEQYtusgc0kgg.jpeg" /><figcaption>National Photo Company Collection, restored by Adam Cuerden / Public domain</figcaption></figure><p>At Bread, an embedded application for completing an eCommerce transaction has a number of important considerations, with security being the absolute top of the list. We’ll discuss “sandboxability” as we consider the various embedding options, meaning the ability to operate an application in total isolation from the page on which it lives. This property is crucial to prevent attackers from taking control of our merchant partners’ pages via techniques like script injection, cross-site scripting (XSS), or man-in-the-middle (MitM), which would allow attackers to watch as users enter their personal info into our application. In the reverse, we also need to be able to bridge across the sandbox boundary securely in order to transmit data like the status of an order or transaction back to our partner’s eCommerce platform so that the order can actually be completed. Not all platforms expose HTTP APIs for this purpose, and so direct communication between host page and embedded app is a requirement. Doing this messaging securely is not trivial, and we’ll dig into this topic deeply in a later article. Last, because Bread allows for white label customization of our financing products, we can’t make assumptions about how they will look until render-time. This last requirement is surprisingly difficult to guarantee consistency around because of cascading styles, and so we’ll consider “style-sandboxing” as its own beneficial property independent of data-sandboxing.</p><p>We’ve mentioned a number of embedding options thus far. Of immediate consideration are the iFrame, Object, and Embed tags, all of which can load HTML documents and run scripts internally. The least dynamic embedding option is the image tag, which while limited also has its advantages (specifically speed, which we will discuss in later articles on performance in this series). Flash, while technically still possible to embed, is not a viable option in production these days due to the security concerns that killed it in the first place. More Javascript-forward solutions like HTML canvas &amp; WebGL, web components, and Webassembly are also tantalizing options for sandbox-like applications. Lets dig into the pros and cons of each, in approximate order of viability of each of these for the purposes of an embedded application like Bread’s:</p><ul><li>Images: Images have a place in our embedding toolkit because they are dead simple and fast as hell. Image loading is prioritized by browsers, and browsers are optimized specifically to quickly decompress and render images quickly. Images are, of course, not themselves applications and so cannot be the only tool we use to build our application with respect to data collection, as they have no sandboxability. That said, dynamically generated images paired with image maps provide a surprisingly flexible tool for stylistic sandboxing. Dynamic data-URIs and serverside headless-browser generated images are topics worthy of their own articles, but these are performance optimizations rather than applications in and of themselves.</li><li>Canvas/WebGl: Another very interesting and unique element, the canvas lets us “draw” whatever we like to the screen. Paired with WebGL, we can create any sort of application we desire, free from the constraints of HTML and CSS, exactly the way we would create a desktop application. However, at its core, we’re still running on the host-page’s Javascript thread, and so this approach (while very fun), is no bueno from a sandboxing perspective. WebGL is also not supported in any IE, which eliminates it from Bread’s use case.</li><li>The Embed and Object tags: These tags exist for embedding multimedia into pages like videos and PDFs. The Embed tag has fallen somewhat out of favor recently, as Object is capable of displaying any file type browsers support. Both have identical properties from the perspective of an embedded application. These tags have the advantage of being prioritized by the browser differently than iFrames, making them somewhat faster to their initial render, but neither supports cross domain messaging back to the host page. This could be worked around via CORS APIs on our own backend, but that is a very roundabout solution, the downsides of which likely outweigh the performance gains.</li><li>Web Components: One of the more exciting upcoming web standards (if you’re like myself and that’s your thing), the web components standard enables the creation of custom HTML elements. You can think of them as native React elements, if that makes things clearer. The most important feature of native web components is that they have completely isolated backing Javascript and CSS, which protects them from JS global namespacing issues and CSS’ cascade. Unfortunately, in the current state of the world, these components are not true black boxes, and there are backdoors into the components from the host page. While these are very useful and very nearly supported in all modern browsers, they cannot be relied upon for security sensitive applications.</li><li>Webassembly: This is a technology that is very exciting and viable for the purposes of sandboxing, but currently the browser support is spotty. Webassembly is a native browser API for executing applications written in any language, and compiled down to the Webassembly bytecode. I’m currently not aware of any programmatic backdoors into the Webassembly black box, which makes me hopeful that this rising standard could be a candidate for creating secure data collection applications. Watch this technology as browser support increases.</li></ul><p>While I am sure this is far from an exhaustive list, we arrive at the reasons we would want to tackle the challenge of utilizing iFrames after exhausting the possible alternatives. The nearly 30 year old iFrame standard certainly has barbs in its API that any piece of technology entering middle age will have (we should all be so lucky!), but for security conscious, whitelabelable applications we have no other choice. Fortunately, this is well understood by the various standards committees, and so while third party cookie policies restrict further month after month, the iFrame remains a viable and important tool that we need to understand — at least until the portals standard is finalized.</p><p>Up next: iFrame performance</p><blockquote>We’re hiring! If you’re interested in learning more about what it’s like to work at Bread, please check out our <a href="http://www.getbread.com/">website</a> and <a href="http://www.getbread.com/life-at-bread">Life at Bread</a> page, and if you’re interested in joining our growing team, feel free to visit our <a href="http://www.getbread.com/jobs">current openings</a> for a list of all open positions!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3dbe4e519b86" width="1" height="1" alt=""><hr><p><a href="https://medium.com/slices-of-bread/iframe-a-love-story-3dbe4e519b86">iFrame — A love story</a> was originally published in <a href="https://medium.com/slices-of-bread">Slices of Bread</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>