6
Developer's Corner / Re: Embeding content on your web pages -- iframes vs native content?
« on: August 31, 2010, 12:13 AM »
Mouser,
To answer your original question concerning the much debated "iframe or direct content injection" topic, let me first begin by explaining my own personal experiences.
While at work, I use a total of 3 methods for content injection and asychronous javascript and xml (ajax) calls. The three methods include:
1. Getting a script by creating a new dom element and injecting it somewhere to the page which forces the clients browser to go get the data. I use this method the most to call php scripts that handle content and echo out javascript. It's ideal for dealing with data clientside (nothing important like passwords etc) but still being able to use server side code because php has access to mysql which can cache your data among other endless possibilities.
2. the traditional ajax methods - creating a new httprequest. i rarely ever use this method anymore.
3. using a combo of YQL (Yahoo Query Language) and #1. - i use this approach the most to scrape data from any web page i need. Yahoo actually caches the results for you which result in faster data returns.
Now you'll notice that none of my methods include iframes. My personal opinion concerning iframes is that they are deprecated. Tons and tons of headaches are created by using methods that include iframes. When traversing the DOM, iframes create more work than necessary. On another note... Iframes are absolutely required when uploading files without reloading a clients browser.
It all depends on your objective... Let me propose an example:
You have a personalized dashboard system for when a customer/user logs in. They have the ability of customizing what "widgets" they want. One customer in particular specifies he wants te latest tweets to display in a beautifully skinned widget box that you've created. the only problem is that you need to get his tweets.
in this example, i would create a few javascript functions to execute when the page is rendering that show a loading bar, use method #1 to create a script element that calls a php file i created to check the last time this users tweets were grabbed. if less than 1 hr ago, i would use mysql to grab the cached tweets and eliminate the extra server connection to twitter (which is overloaded constantly and could result in a timeout or hang.) if the users tweets were grabbed more than 1 hr ago, php can use cURL to grab the new tweets from the server and echo out an object response using JSON so that you can populate the widget with the data the user needs in an easily accsssible manner.
Anyways, let me know if you have questions. I'm uncomfortable typing from my iPhone and can provide more help at a better hour tomorrow ;)
To answer your original question concerning the much debated "iframe or direct content injection" topic, let me first begin by explaining my own personal experiences.
While at work, I use a total of 3 methods for content injection and asychronous javascript and xml (ajax) calls. The three methods include:
1. Getting a script by creating a new dom element and injecting it somewhere to the page which forces the clients browser to go get the data. I use this method the most to call php scripts that handle content and echo out javascript. It's ideal for dealing with data clientside (nothing important like passwords etc) but still being able to use server side code because php has access to mysql which can cache your data among other endless possibilities.
2. the traditional ajax methods - creating a new httprequest. i rarely ever use this method anymore.
3. using a combo of YQL (Yahoo Query Language) and #1. - i use this approach the most to scrape data from any web page i need. Yahoo actually caches the results for you which result in faster data returns.
Now you'll notice that none of my methods include iframes. My personal opinion concerning iframes is that they are deprecated. Tons and tons of headaches are created by using methods that include iframes. When traversing the DOM, iframes create more work than necessary. On another note... Iframes are absolutely required when uploading files without reloading a clients browser.
It all depends on your objective... Let me propose an example:
You have a personalized dashboard system for when a customer/user logs in. They have the ability of customizing what "widgets" they want. One customer in particular specifies he wants te latest tweets to display in a beautifully skinned widget box that you've created. the only problem is that you need to get his tweets.
in this example, i would create a few javascript functions to execute when the page is rendering that show a loading bar, use method #1 to create a script element that calls a php file i created to check the last time this users tweets were grabbed. if less than 1 hr ago, i would use mysql to grab the cached tweets and eliminate the extra server connection to twitter (which is overloaded constantly and could result in a timeout or hang.) if the users tweets were grabbed more than 1 hr ago, php can use cURL to grab the new tweets from the server and echo out an object response using JSON so that you can populate the widget with the data the user needs in an easily accsssible manner.
Anyways, let me know if you have questions. I'm uncomfortable typing from my iPhone and can provide more help at a better hour tomorrow ;)