AJAX TipsThere are Ajax based applications that will require cookies from their user. By enabling cookies on the user side, the application can easily interact with the user since personalized information could be extracted. This will significantly increase interactivity since cookies will practically inform the application regarding the user’s preferences.
Enabling cookies in the application will also help the developers protect their application since they will know who will access their application and what actions have been done on the application. Cookies could be controversial in terms of user security, but it enables personalization of interaction as well as application protection.
JavaScript has the capability of testing the browser if it can enable cookies. Its ability to interact with user is well known partly because it can use cookies to its own advantage. Although there are security challenges in JavaScript, this is somehow expected and could be easily handled.
Again, the use of cookies is not just to interact better with the user, it can also be used to protect the application from users who just wanted to harm the application or even steal very important data. With JavaScript enabling cookies, it can protect the application while being interactive with users.
There are three stages every developer has to deal with if they wanted to implement cookies in their Ajax based application.
The first challenge is browser incompatibility. It’s already a known fact that IE and the rest of the browsers do not essentially agree on how to deal with certain functions. IE always have a knack of going the longer route rather than simple acknowledging the simplified function offered for most non-IE browsers. Of course there is a way of dealing with incompatibility and this is imperative so that the next challenge for cookies could be handled.
The second challenge is the browser version. This is actually based on a single function – navigator.cookieEnabled. This function properly enables cookies in most major browsers.
However, this function could only work on IE v.4 and above and Netscape based browsers v.6 and above. That means you need to use another function to enable the cookies in this browser. But that would only create more functions and could easily confuse the developer on how to properly configure the cookies in every browser.
The third challenge is actually the simple alternative to the above recommendation. Although navigator.cookieEnabled could effectively trigger cookies in the browser, its inability to detect the browser versions might disable the entire application.
The solution for this problem is to execute a test value in the application before implementing the actual value. It’s just a small value – with little to no footprint but could trigger the cookies in the browser along with the version. By testing the browser first, the application could react accordingly based on the type of browser and its version.
By properly detecting cookies in the browser, developers should be able to personalize the experience and even improving browsing security of their users in their Ajax based application.