Wednesday, July 16, 2014

Importance of DOCTYPE declaration in (X)HTML

From my experience, I can remember many cases where I knew for sure that I have written a HTML document correctly with Javascript and CSS, still it is not rendered properly in the browser. Few weeks back, I encountered the same problem and like every time it is the DOCTYPE declaration which is the reason for this mess. So. I thought of sharing my knowledge regarding DOCTYPE through this post. DOCTYPE is a declaration that we usually find in the very beginning of an HTML document (it applies to XHTML too). The first thing to remember here is that DOCTYPE is not a HTML tag. It provides some information to the browser regarding the version of HTML that has been used in the document. In other words, DOCTYPE is a meta-information for the HTML document.

What happens if we don’t specify the DOCTYPE declaration?
A DOCTYPE declaration tells the browsers to render a HTML document in standards and compliant mode. It ensures that the rendering of (X)HTML, CSS, and DOM is done in a standard way. Browsers make many assumptions and guesswork while rending a (X)HTML. If we do not specify any DOCTYPE declaration, browsers will use the “Quirks” mode and render the (X)HTML according to its own proprietary logic. Even if a (X)HTML has a valid DOCTYPE declaration but has validation errors against that DOCTYPE, the browsers may not complain and continue render it. For example, the (X)HTML below fails validation but it is rendered correctly in browsers.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="">
<title> Test </title>

     <p>HTML content..</p></br>


Only if we have a valid DOCTYPE declaration and no validation errors with respect to the declared DOCTYPE, we can rest assure that the (X)HTML document will be properly rendered across browsers without writing any browser-specific tag. A list of valid doctypes can be found here.

The doctype declaration is significantly simplified in HTML 5. The valid declaration of HTML 5 doctype is:-

<!DOCTYPE html>

A simple (X)HTML document in html 5 will be as follows:-

<!DOCTYPE html>
<title>Document Title</title>

The content of the Document


Adding a DOCTYPE declaration to (X)HTMl documents is always the best practice. Most of tools we use to create (X)HTML documents do add a DOCTYPE declaration by default and also checks for the validity of the document against the declared DOCTYPE. The documents should only be published when there is no validation errors against a declared DOCTYPE.

Friday, July 11, 2014

From distributed caching to in-memory data grid

Distributed caching is around since the late 1990s and has been continually evolving since then. Many new features have been added to distributed caching frameworks but simply accessing data in key/value pairs from memory was not fulfilling the expectations of the customer. In fact, storing data in key/value pair does not add much value but processing of the data do add value. So the customers were expecting to move the computation of data closer to data itself. Data grids addressed this requirement by adding features to be able to do computations on the cached data. For example data grids provide feature like querying data in the memory using standard SQL syntax, data-indexing, providing map-reduce based processing, support for various complex data models (document, relational) etc.

Distributed Caching

Since late 1990s, distributed caching technologies evolved continuously by add more and more features. While the first generation distributed caching provided simple cache clusters with a sophisticated hashing algorithm to keep track of the data. In the next generation of distributed caches, we find advanced features like high availability using partitioned or replicated architecture, ACID transactions, distributed locking, asynchronous events and active backups.

Data Grid

Although, distributed caching has evolved and matured over the years, what was missing was to bring the computation of cache data to in-memory. Data has become more and more complex over the years. New requirements like providing dynamic scalability, database-like persistence, map-reduce based processing, SQL like querying features, support for different types of data model like document, json, relational etc were coming up. Data grids addressed these requirements and also provided additional features like capability for monitoring and management, policy and security enforcement, support quality of service and easy integration with existing enterprise applications. Growing adaption of data grid is bringing in more sophisticated requirements and higher customer expectations.
The important thing to note here is that Data Grid is not backed by any specification or industry standards. So the growth of Data grid is completely based on customer requirements. Few popular Data Grid tools in terms of customer adoption are:-
  • VMWare Gemfire
  • Oracle Coherance
  • Gigaspaces-xap

Along with the previous 4 posts, I tried to cover as much as possible about caching. There are many specific areas which I'll address going forward like tools comparison. Please comment if you find anything missing or need more information and explanation.