Alex Rivera | Logout

Widget - Iframe versus JavaScript

Asked 2009-02-11T06:36:31.250
56

I have to develop a widget that will be used by a third party site. This is not an application to be deployed in a social networking site. I can give the site guys a link to be used as the src of an iframe or I can develop it as a JavaScript request.

Can someone please tell me the trade offs between the 2 approaches(IFrame versus JS)?

Edit
Report

2 Answers

3

If the widget can be embedded in an iframe, it will be better for the frontend performance of the hosting site as iframes do not block content download. However, as others have commented there are other drawbacks to using iframes.

If you do implement in javascript, please consider frontend performance best practices when developing. In particular, you should look at Non blocking javascript loading. Google analytics and other 3rd party widget providers support this method of loading. It would also help if you can load the javascript at the bottom of the page.

answered 2011-03-15T22:54:13.057
2

Nice to know that it's not to be deployed in a social networking site... that merely leaves the rest of the web ;-)

What would be most useful depends on your widget. IFrames and javascript generally serve quite different purposes, and can be mixed (i.e. javascript inside an iframe, or javascript creating an iframe).

  • IFrames got sizing issues; if it's supposed to be an exact fit to the page, do you know that it renders the same on all browsers, the data won't overflow it's container etc?
  • IFrames are simple. They can be a simple, static HTML-page.
  • When using IFrames, you expose your widget quite plainly.
  • But then again, why not have your third party site simply include the HMTL at a given url? The HTML can then be extended to contain javascript when/if you need it.
  • Pure Javascript allows for more flexibility but at the cost of some complexity.
answered 2009-02-11T06:59:31.070

Your Answer