DEV Community

Meredith Hassett
Meredith Hassett

Posted on

Why are we still using iFrames?

A few months ago, I took over the Corvid by Wix StackOverflow tag to help answer questions about Corvid (formerly Wix Code). One of the common themes I saw popping up was people loveee using iFrames on their Wix sites. And for a second I thought maybe 2020 is all a dream and I'm actually back in 2008. But then I pinch myself, and it hurts so I'm awake and it really is 2020.

bad iframes

To figure out why people are still using iFrames, I went to the one place I find all my information...Google Search. The main themes I found there were people are using iFrames to:

  1. not have to deal with CORS and giving 3rd party sites/services unrestricted access
  2. it's easier to pull UI elements across with iFrames
  3. Advertising and Marketing
  4. maybe the 3rd party you are working with doesn't provide an alternate solution

But using iFrames does cause problems for developers. iFrames are one way, so there is no way to get responses from any embedded forms. This makes it harder for the ever-growing-in-popularity event driven programming. Additionally when we all have 3 different screen sizes in our pockets/bags/homes, iFrames aren't inherently responsive and can break the user experience on a mobile site. And from an SEO perspective, they may not help you as the content cannot always be indexed.

woman coding

So in today's modern world of REST APIs and GraphQL, why are you still using iFrames? I am hoping to start a series exploring this topic, so please share you positive or negative iFrame experiences in the comments!

Top comments (3)

Collapse
 
asimen1 profile image
Asaf

It's not true to claim "iFrames are one way, so there is no way to get responses from any embedded forms" - that's what postMessages are for! To simply working with those...

Btw I wrote an open source library to simplify communication between frames - it’s called iFramily (github.com/EkoLabs/iframily).
Basically it has a simpler API than postMessage, which includes Promise-based responses, message queuing, and managing the connection until both frames are ready to talk. It also takes a responsible approach to security...

Would love to hear your thoughts!

Collapse
 
moopet profile image
Ben Sinclair

iframes can be responsive. The parent page can respond by giving them as much room as they need, and they in turn get access to their own media width.

You can vertically resize them with a script to post messages to the parent (though this does mean you require javascript and access to add one part of it to the iframe as content).

Collapse
 
tlylt profile image
Liu Yongliang

A web dev newbie here. The last time I used iFrame was to make podcasts of a podcasting platform shareable, allowing the content to be easily embedded onto other people’s website. So a particular podcast can be presented with our customised player and our styling, on an creator’s personal website. I guess this is quite typical for such platforms (Soundcloud/Spotify) etc.

I would say one problem being making iFrame safe, without security loopholes open for attacks. One thought that I had the moment I discovered iFrame was, it is really cool - I can potentially make a website simply composed of multiple iFrames, much like those website builders 😂