Device Detection with WURFL

Device Detection with WURFL

Tutorial Details
  • Technology: Mobile Web
  • Difficulty: Intermediate
  • Completion Time: 30 Minutes

This tutorial will introduce you to WURFL and demonstrate how it can be used for device detection and cross-platform mobile web development.


What is WURFL?

WURFL is a Device Description Repository (DDR) which serves as a central source of device information for mobile web applications. It contains descriptions of thousands of mobile devices that can be used in any application, free or commercial

ScientiaMobile is the company behind the project, which stands for Wireless Universal Resource File. WURFL is recognized as the de-facto standard in the area of Device Description Repositories. The project began in 2002, with the intention of tackling the issues of mobile device fragmentation. It seeks to do so by providing developers across the world with a common set of device information.

WURFL has the following editions:

  1. Java Edition
  2. PHP Edition
  3. .Net Edition (Also called NuGet)
  4. Database Edition

WURFL is available as an open source project and also with commercial licenses. The free version is generally used by open-source projects, whereas websites belonging to licensee organizations go for commercial version.


Wireless Abstraction Library (WALL)

WALL (Wireless Abstraction Library) is a JSP tag library that lets a developer author mobile pages similar to plain HTML, while delivering WML, C-HTML or a XHTML Mobile Profile to the device from which the HTTP request originates. The proper format is chosen depending on the actual capabilities of the device sending the request.

WALL Markup

The figure on the left shows the different markup languages. Since the coders design the application to support all the available devices, the available domain for coding is the area of intersection. Due to introduction of more and more devices and the difference in device support and features, this region generally becomes smaller and smaller.

WURFL addresses this issue by detecting the device type and then delivering suitable markup. The figure on right demonstrates the available markup range for the coders to develop, which is the sum of all the markup regions.

WURFL contains 7,000+ unique devices and thousands of firmware variations, representing nearly every mobile device on the market worldwide!


WURFL Flow

Once an application request from a device reaches the web server, the WURFL framework detects the device type and produces markup generated specifically for the device. The diagram below shows the request flow for web applications having WURFL integration enabled:

WURFL Project Flow

WURFL Structure

The configuration files for WURFL are written in XML and consist of a list of devices with their capabilties. WURFL.mxl has a list of all the devices available, along with the features embedded within the file itself. Other files vary with different versions of WURFL.

WURFL Structure

The diagram above represents the WURFL structure for the Java version. The configuration file sits on the root folder of the web servers where the application resides. Therefore, all the pages in the web server can make use of WURFL easily.

To start working with WURFL, you need to download the configuration file from the WURFL site. This configuration file needs to be hosted directly inside the root folder of the web server (as shown in the diagram above).


Groups & Capabilities

A Group in WURFL is a set of similar features clubbed together. For example, a group could include Markup, Image Format, Sound Format, Display, Ajax Support, Cache Support, CSS, SMS, MMS, etc. for a particular subset of devices.

A Capability is a unique feature that defines an individual functionality supported by a mobile device


WURFL Functionality

The sample code below is from the WURFL repository file (WURFL.xml), which contains groups and capabilities for a device:

<device user_agent="Nokia3650" actual_device_root="true" fall_back="nokia_generic_series60" id="nokia_3650_ver1"><br/>
<group id="image_format"><br/>
<capability name="bmp" value="true"/><br/>
<capability name="colors" value="4096"/><br/>
</group><br/>
</device>

This is the configuration file which is queried for device information. So, if a new device is introduced into the market, we need to add the information in this file.

The functionality of WURFL can be explained in two steps :

  1. Device detection : When a request from a device comes in, the WURFL repository file is queried for the USER_AGENT value. This is a unique value for each device.
  2. Return capability Value : Once the USER_AGENT is obtained, the repository is queried again and corresponding groups and capabilities are obtained. Then the markup is created for the requesting device that corresponds to the capability values. If the capabilities are not found within the id for USER_AGENT, the capabilities are obtained following the inheritance using the id from the FALL_BACK value. The inheritance chain continues till the capability values are available for markup.

Including WURFL

WURFL can be included in various formats like PHP, JSP and .NET.

The example below shows how we include a WURFL repository to a JSP page.

A WURFL enabled page must include two files:

  • /WEB-INF/tld/wall.tld: This tag library descriptor page is included at the top of the page.
    <%@ taglib uri="/WEB-INF/tld/wall.tld" prefix="wall" %>
    
  • /WEB-INF/tld/c.tld: This page is included just above the body tag
    <%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>

The example below demonstrates how WURFL works and shows how a WURFL enabled JSP page hosted in the web server might like look:

<%@ taglib uri="/WEB-INF/tld/wall.tld" prefix="wall" %>
<wall:document>
	<wall:xmlpidtd />
	<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
	<wall:load_capabilities />
	<wall:body>
<wall:body>
	<wall:block>
	<c:choose>
		<c:when test="${capabilities.resolution_width >= 700}">
			<iframe frameborder="0" scrolling="no" src="pageA.html" ></iframe>
		</c:when>
		<c:otherwise>
			<iframe frameborder="0" scrolling="no" src="pageB.html"></iframe>
		</c:otherwise>
	</c:choose>
	</wall:block>
 </wall:body>
</wall:document>

In this example, if the page is requested by a web browser whose resolution width is more than 700, the first part of the condition will be executed and pageA.html would appear on the iframe. Otherwise, pageB.html would appear.

Similarly, we can make use of capabilities to query the device properties and provide markups, display styles, images, and and also manipulate content based on device type.


Who is Using WURFL?

Currently, a large number of companies are using WURFL for development of mobile websites. These include companies who are large and medium content providers, but the most popular usage of WURFL is in companies that are small content providers. Some of the most popular companies that make use of WURFL are Vodafone, Mobile Galleries, and Pepsi UK.

Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • RAKESH

    gr8 job Pranay..its really good article !!!

    • Pranay

      Thanks Rakesh..

  • Sourabh

    Its grt work well done. Very useful for users….

    • Pranay

      Thanks Sourabh

  • http://51degrees.mobi James Rosewell

    Good introduction to what is possible in the world of server side detection. Additional solutions include 51degrees.mobi at …

    http://nuget.org/packages?q=51degrees&sortOrder=package-download-count

    …and for the Apache world…

    http://fiftyone.apachemobilefilter.org/

  • http://certifiedfreelance.com Florante

    Very informative. Another contender that you can add for mobile detection and redirection purpose is http://www.handsetdetection.com The javascript option is the quickest way to do it. API kits are also available. Richard is doing a great job keeping it up as well as responding to support questions.

  • Neha

    wow..Nice One Pranay..Keep Up the Good work :)

    • Pranay

      Thanks Neha

  • Syaz

    Their new licensing scheme is a huge turn off though. We stopped using it ever since.

  • jared

    It would be great to mention that this is no longer a free solution.

    licensing announcement can be found: http://tech.groups.yahoo.com/group/wmlprogramming/message/34311

  • http://dailytut.com boopathyD

    WURFL- new term for me. Nicely explained!! thanx :D

  • leela

    Wow…!!

    May be this one is more explanative than what is on WURFL site.’ WURFL’ increases the scope of capability detection of mobile devices. Nice explaination PRANAY RANJAN. Hope to see more articles from you.

  • Davide

    There is an open source project Apache Mobile Filter (http://www.apachemobilefilter.org), is a module of apache included in http://modules.apache.org, and uses several commercial device repository like WURFL, DetectRight and 51Degrees.

  • http://espirit.in/ Jinesh

    Excellent article, well written and the simple narration is very easy to comprehend.