Sunday, August 23, 2009

DATA URI

To fetch each file (images on your website, any plain text file) browser has to make separate http request with server. So the thumb rule to optimize any web application is to reduce the number of http requests.So lesser the number of requests made fast your application will load.
We use different techniques such as CSS Sprites to reduce these http requests.
Data URL is one of such techniques. And is supported in all major browsers including Internet Explorer 8.
There are many URL schemes available eg http, ftp,mailto: etc. each scheme has its own meaning. Similarly the data: URL scheme is a way to embed “immediate data” as if it was included externally.

Syntax:
data:[<mediatype>][;base64],<data>
The mediatype is a MIME type string, such as "image/jpeg" for a JPEG image file.
If omitted, defaults to text/plain;charset=US-ASCII
If the data is textual, you can simply embed the text (using the appropriate entities or escapes based on the enclosing document's type). Otherwise, you can specify base64 to embed base64-encoded binary data.

Examples:
data:,Hello%2C%20World!
Simple text/plain data
data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D
base64-encoded version of the above
data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E


Embedding an image in the HTML using data url:
E.g.
<img src="data:image/gif;base64,R0lGODlhEAAOALMAAOazToeHh0tLS/7LZv/0jvb29t/f3//Ub/
/ge8WSLf/rhf/3kdbW1mxsbP//mf///yH5BAAAAAAALAAAAAAQAA4AAARe8L1Ekyky67QZ1hLnjM5UUde0ECwLJoExKcpp
V0aCcGCmTIHEIUEqjgaORCMxIC6e0CcguWw6aFjsVMkkIr7g77ZKPJjPZqIyd7sJAgVGoEGv2xsBxqNgYPj/gAwXEQA7" 
width="16" height="14" alt="embedded folder icon">
 
Useful resourcesl:
https://developer.mozilla.org/en/The_data_URL_scheme

Wednesday, July 29, 2009

Emulate IE8 as IE7

IE8 has come up with many updates that might affect your existing application/website design. So if you really running out of time and need to fix these issues as soon as possible then what you could do is actually inserting a meta tag in head section and asking your IE8 to render the page as IE7 or any other IE version.
<meta http-equiv="X-UA-Compatible" content="IE=…." />
There are two ways of using this meta tag:
  1. <meta http-equiv="X-UA-Compatible" content="IE=7"/> 

  2. <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>
IE=7 : Display in IE7 Standards mode; Already supported in the IE8 Beta 1 release
IE=EmulateIE7 : Display standards DOCTYPEs in IE7 Standards mode; Display quirks DOCTYPEs in Quirks mode;
There are two ways to implement this tag:
  • On a per-site basis, add a custom HTTP header
X-UA-Compatible: IE=EmulateIE7
  • On a per-page basis, add a special HTML tag to each document, right after the tag
Implementing the HTTP header is beneficial if a site owner wants most of their site to render as it did in IE7 or if there are no plans to update site content. Inclusion of this header honors any Quirks mode pages that belong to the site.
Using the meta-tag on a per-page basis is beneficial when the publisher wants to opt-in specific pages to render as they did in IE7.
NOTE: The X-UA-Compatible tag and header override any existing DOCTYPE. Also, the mode specified by the page takes precedent over the HTTP header. For example, you could add the EmulateIE7 HTTP header to a site, and set specific pages to display in IE8 mode (by using the meta-tag with content=”IE8”).
Using the IE=EmulateIE7 compatibility tag is a simple way for users to continue their current experience when browsing your site until you can update with more standards-compliant content.
Useful resources:
http://msdn.microsoft.com/en-us/library/cc288472%28VS.85%29.aspx