Friday, June 10, 2011

Mobile Performance Techniques > Images


This blog talks about the optimization techniques to render an image in Mobile browsers.

1. Make sure the Images are not resized in the Mobile, but do it in the Server itself.

   Say when a image of 100x100 size is loaded into a page with 50x50 as width and height attributes. The browser has to work on minimizing (or maximize in case the attribute is larger than the actual size) this image to specified value. This may be a minuscule task/resource utilization in desktops, but this cause quiet an impact in rendering the page with Mobiles.
So make sure the Image is resized in the server end than at the browser end; and make sure the width & height attributes are exactly same as the actual Image width & height.
This mechanism would also save the data transfer over the wire, which is a major advantage in Mobile networks.

The above info might lead you to think about avoid mentioning the width-height for an IMG tag, to have a less hassle over sync'ing the IMG width-height attribute with the actual image size. There is a drawback for this too.
  • Causes slower rendering/Multiple reflow (or repaint/realignment) of the page.
        If the width-height attributes are not specified the browser will not know the exact space to be allocated for the Image. Hence it will download the image and then find its width-height attributes and then rerender/reflow & repaint the page. Repaint is not a costly process but reflow is - to an extent.
        Apart from that the ALT | TITLE elements of the IMG tag will take up its own space, which may be less than or greater than the actual image space.

       The end user will see a page with some layout and once the images are loaded there will be another layout (may be the final one). But if there are more than one image, the user will see the layout changing multiple times, untill all the images are downloaded.

  • Unfriendly to SEO
      The Search engines give some weightage to width-height attributes apart from Title/Alt fields. As the Search Engines use these attributes to bucket it into thumbnail, small, medium, huge images.
      In addition to bucketing, these attributes help rendering the page faster, which makes the Search Engines to give higher ranking to the page w.r.t 'Page Load Speed'.

All the above mentioned techniques are applicable to Mobile browsers as well - with even a higher priority than desktop browsers.

2. Sprite the images

    CSS Sprites have become a must-do for optimizing the websites. This technique helps to combine multiple images to one and also displays the image as a background image of the HTML element.
    With Sprite'd image there will be only one network call in place of multiple image calls. Also the image is loaded only when that image is under visible space i.e. If the website is vertically long, and the sprite'd images appear way below the visible area, then this image will not be loaded. When the page is scrolled down to make the sprite'd image visible the browser will trigger a Sprite'd image dowload at that point. This reduce the page load time to a good extent.

   Many Mobiles support Sprites, but not all. Wurfl will help find this feature for mobiles and based on the capabilit (for iPhone) CSS Sprite'ing can be used for such mobiles.

3. Use Data URIs inplace of Images if there are only few set of images and are reused across pages.

    These can be specified in the CSS file itself, so that they get downloaded with CSS and cached.
    The Data URIs can also be stored in the Local Storage and retrieved as needed.

4. Compress the Images

    Not always the Images generated out of Photoshop or any Photo Creaters compress them or compress them well. They may have separate utilities to do the compress better.
    I found PngOut utility to be useful and simple enough to compress a PNG image, generated out of Photoshop.
    Some of the images were compressed to upto 60% lesser, saving huge KBs. I found PngOut to be better than PngCrush utility atleast for the PNG images I wanted to compress.

    I haven't R&D'd on the compressing utilities for other image types.


Wednesday, June 1, 2011

Semantics and SEOs


I recently attended a Developer Summit (GIDS) and got bit by the 'Semantic Web' after the presentation by Scott Davis. Since then I had been looking out for the semantics present in web pages and how the Search Engines are consuming the same.

Google

And couple of days back I landed on searching "events in bangalore today" in Google. In the result page I noticed the 4th (EventFul.com) and 7th (IndoBase.com) record were provided with additional info in the search page itself.

The EventFul.com page (4th record) has a list of events happening in the Bangalore city. The HTML tags for the events are appropriately tagged with vevent semantics. (Note: The vevent semantic uses hCalendar properties). The properties used are: vevent, url, dtstart (value-title, title) & location. All these attributes are specified inside html-class attribute.








e.g:


<table>
<tr class="vevent">
   <td class="photo">
      <a href="http://eventful.com/bangalore/events/alphonso-mango-festival-/E0-001-038915626-1">AN IMAGE TAG</a>
   </td>
   <td>
     <h2><a class="summary url" href="http://eventful.com/bangalore/events/alphonso-mango-festival-/E0-001-038915626-1">Alphonso Mango Festival</a></h2>
     <strong><span class="dtstart"> 1 May <span class="value-title" title="2011-05-01T00:00:00"></span></span></strong>
     <p class="place location">Mama Mia , Church Street</p>
   </td>
</tr>
</table>



The detail page for the events also presented with the same semantics detail for every event. In addition they also have added 'geo-location' info for the venue with 'geo' property, which again is part of HTML-class attribute.
Lets peep into the IndoBase.com (7th record) site. Surprisingly there is no semantic with vevent or hcalendar! But I noticed the URL itself contain the info.
The all events page URL is: http://www.indobase.com/events/city/bangalore-india.php. This can be split as domain / events / city / value-for-city-with-country.
One of the details page URL is: http://www.indobase.com/events/details/photo-today.php. This can be split as domain / events / details / eventName. There is no other info for dtstart, url or location etc. Yet Google is able to identify the details. Great!!
I suppose IndoBase.com might be using RDFa format.

Yahoo!

After learning these nitigritties about Semantices, I thought of exploring Yahoo! search for the same. It presented a very interesting output!

Yahoo! search did not provide any additional info for each Search result. But if you notice the left-side navigation, you will see Eventful link with the favicon of EventFul.com website, right below 'Show all' link.
This link provides results only from the EventFul.com website alone. IndoBase.com is appearing on the second page of Yahoo! search result, again no additional info related to this website is seen. I am not sure what made the 'EventFul' link appear in the left-nav in Yahoo!, but surely the semantics should have played a role in there.









Bing


It seems agnostic to semantics :(