Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Widget design. What is better: IFrames or Javascript? [closed]

Tags:

php

iframe

widget

I am in the beginning stages of designing a widget and a design question came up for what is more advantageous - to have it as an IFrame or to use another technology.

Has anyone built widgets before to be embedded into other sites? What is the best was to design/architect them? Any particular good practices?

Thanks, Alex

like image 220
Genadinik Avatar asked Mar 19 '11 03:03

Genadinik


People also ask

What is the difference between a widget and an iframe?

The difference between the iframe and widget embed options is that the widget can take on CSS properties of the page it is embedded on, and the iframe will not.

Is iframe recommended?

Google recommends refraining from creating iframes. At there Webmasters Help Forum, Google clearly stated that iframes may cause problems for them: IFrames are sometimes used to display content on web pages. Content displayed via iFrames may not be indexed and available to appear in Google's search results.

Are iFrames still used?

iFrames are an HTML tag and have been around for absolutely ages having been introduced back in 1997. Despite their age, they are still commonly used and are supported by all modern browsers.

Will iFrames be deprecated?

IFrames are not obsolete, but the reasons for using them are rare. Using IFrames to serve your own content creates a "wall" around accessing the content in that area. For crawlers like Google, It's not immediately clear that cotent in an iframe will be ranked as highly as if the content were simply part of the page.


2 Answers

In general, if you are going to be using dynamic data from your server you should use an iframe, if not you shouldn't.

Advantages of iframes:

  • Easy to include data from your server
  • Can use stylesheets without concern for selector collisions
  • Your user's don't have to worry about the security concerns associated with running your javascript in their page
  • You don't have to render your widget's html with javascript

Advantages of JS only widget

  • You can create snappier and more natural interfaces that don't require a second full page load and can easily be made to fit a container. This means you can avoid nested scrolls.
  • Less load will be put on your server
  • Your widget can interact with the rest of the page it is embedded in
  • Your user has more control over the functionality of the widget.

If you're still having trouble deciding you should look at how other similar widgets are built and also consider the implications of same origin principle.

like image 116
tilleryj Avatar answered Sep 18 '22 17:09

tilleryj


I have embedded several widgets into my personal website. I will briefly go through a few examples:

Facebook comments

// Facebook comments
<fb:comments xid="12345678" numposts="3" width="380"></fb:comments> 

// Facebook initialization
<div id="fb-root"></div> 
<script> 
    window.fbAsyncInit = function() {
        FB.init({appId: '123456789123456789', status: true, cookie: true, xfbml: true});
    };
    (function() {
        var e = document.createElement('script'); e.async = true;
        e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
        document.getElementById('fb-root').appendChild(e);
    }());
</script>
  • I personally dislike the use of custom XML tags.
  • A fairly overkill approach. Perhaps useful if you provide more functionality than just a simple widget.

Twitter

// Twitter tweets
<div id="tweets-container"></div>
<script> 
    new TWTR.Widget({
        profile: true,
        id: 'tweets-container',
        loop: false,
        width: 250,
        height: 200,
        theme: {
            shell: {
                background: 'transparent',
                color: '#3082af'
            },
            tweets: {
                background: 'transparent',
                color: '#444444',
                links: '#1985b5'
            }
        }
    }).render().setProfile('TwitterUsername').start();
</script>
  • Clean and neat javascript.

Google Chatback badge

// Google Chatback badge
<iframe src="http://www.google.com/talk/service/badge/Show?tk=z01q6amlq6ob76db19rdnikg1pbce3ff3ln9076tc8unrn37r3gmje9pf3gvl80num7ta10tv34ou7has2u2th5btn3uoouvpcufnqolc1mj77nmgld5mm3qf3reqkd3jqcvemqlpr8b04pf0qaf7osm10lo6kioji176dpcn&amp;w=200&amp;h=60" allowtransparency="true" width="200" frameborder="0" height="60"></iframe>

Google Calendar

// Google calendar widget
<iframe src="http://www.google.com/calendar/embed?showTitle=0&amp;showCalendars=0&amp;showTz=0&amp;mode=WEEK&amp;wkst=2&amp;hl=en&amp;src=nicohome%40gmail.com&amp;color=%232952A3&amp;ctz=Europe%2FHelsinki" style=" border-width:0 " width="557" height="445" frameborder="0" scrolling="no"></iframe> 

Delicious Bookmarks

// Delicious bookmarks
<script type="text/javascript" src="http://feeds.delicious.com/v2/js/Nicodemuz?title=My%20latest%20bookmarks&icon=s&count=10&bullet=%C2%BB&sort=date&name&showadd"></script> 

Summary

  • As we can see, both javascript and iframes are used heavily in the industry.
  • If you need to render content into more than one place, use javascript, as an iframe can only be rendered into a single place.
  • If your widget does not require javascript to work, then going with a iframe may be more suitable, as then your widget would also work on browsers with javascript disabled.
like image 40
Nicodemuz Avatar answered Sep 21 '22 17:09

Nicodemuz