How to prevent browser caching
There are many ways you can prevent browser caching.
One of them is to include following meta tags, place these tags in head section of html document.
<META HTTP-EQUIV="Pragma" CONTENT="no-cache"> <META HTTP-EQUIV="Expires" CONTENT="-1">
For ASP pages use following script at the extreme beginning of the page
<% Response.CacheControl = "no-cache" %> <% Response.AddHeader "Pragma", "no-cache" %> <% Response.Expires = -1 %>
In case of JSP pages use following code
<%
response.setHeader("Cache-Control","no-cache");
response.setHeader("Pragma","no-cache");
response.setDateHeader ("Expires", -1);
%>
If you are generating your response in java or some other languages then you need to set following parameters in response header.
response.addHeader("cache-control", "no-cache");
response.addHeader("pragma", "no-cache");
response.addHeader("expires", "-1");
All of the above method works on the response of the particular page and tell browser not the cache the response.
There is another way of telling browser to make a fresh request and don’t use the cached content for the page if any. This is done by appending some random characters to requested url. Below is sample code
<script> var url = "http://techpitcher.com"; url += "?preventCache="+ Math.floor(Math.random()*100000); </script>
This will create a random url every time and won’t allow browser to use cache content.
jQuery – A lightweight JavaScript Library
jQuery is JavaScript library that simplifies lots of work done in JavaScript. jQuery makes HTML document traverse easy. It can provide ajax support to your website. There are lots of site which provides jQuery plugins (plugin for validation, animation, cookies, events). The most important point to remember is that by using jQuery you can easily get multiple browser compatibility.
There are three downloads available
1. Minified and Gzipped (Used in production)
2. Packed version (This version is not gzipped)
3. Uncompressed (Used in testing and learning)
Reference
http://jquery.com
Fiddler: Http debugging proxy
Fiddler is an HTTP debugging proxy that logs all HTTP traffic between your computer and the Internet. Fiddler is simpler in use and provides lots of information regarding the data flow.
1. It allows you setup break points on incoming and outgoing request/response.
2. Modify incoming and outgoing response/ request to test some edge cases.
3. Gives complete information about request, response headers.
4. Provides cookies information.
5. Round trip time taken by request.
6. Can simulates slow internet connect speed. It helps in testing web applications in slow internet connections.
Click here to download fiddler

String Number conversion in JavaScript
Number to String conversion
To convert a number to string you can append an empty string or you can use toString() method. toString() method is not supported by older browsers.
var num = 30; num = 30 * 5; // 150 str = num + ""; // or str = num.toString();
String to number conversion
To convert a String to number, you can perform arithmetic operations like (*, / or -) such that it doesn’t alter the given string value. You might have noticed that I have not included ‘+’ in the above list this is because that JavaScript uses ‘+’ sign for string concatenation so adding ‘123′ + 0 will result into ‘1230′ and not 123. We can also user Number() function to perform the conversion. This is bit slower than any of the above options because this make explicit call to a function to perform conversion. But if you are using this option then it makes very clear that what your code is intended to do. So in my opinion if you are not worried about the performance then you can use Number() function as it will make code very clear.
var str = '123' num = str * 1; num = str - 0; num = str/ 0; num = Number(str);
If you try any of the above method on a text field which doesn’t contain valid numeric fields then you will get an ‘NaN’ as the result. So be careful
How to Enable/Disable Input element in JQuery
To disable input elements (checkbox, radio button, text box, button etc) in jquery, you need to set disabled attribute.
// check box
$("#check_box_id").attr("disabled", "disabled");
// radio button
$("#radio_btn_id").attr("disabled", "disabled");
// Text box
$("#text_box_id").attr("disabled", "disabled");
// button
$("#btn_id").attr("disabled", "disabled");
To Enable the input elements (checkbox, radio button, text box, button etc) , we need to remove disabled attribute. This can be done in the following way.
// check box
$("#check_box_id").removeAttr("disabled");
// radio button
$("#radio_btn_id").removeAttr("disabled");
// Text box
$("#text_box_id").removeAttr("disabled");
// button
$("#btn_id").removeAttr("disabled");
Initializing Array in JavaScript
There are many ways we can initialize the Array in the JavaScript. JavaScript is a loosely types language. This means you need not worry about data type while storing them in Array. It can store any data type in a single array. Also you don’t need to provide the size of Array at the time of creation of Array. JavaScript will automatically adjust size of array according to the requirement. You can create Array by following declaration.
var array = [];
Another way of creating Array in JavaScript is
var secondArray = new Array(5);
This will create an Array of length 5.
Initializing an Array
You can initialize Array with pre defined data.
var dataArray = ['Tech', 'Pitcher', 'And', 'You'];
Restoring Conventional Browser Navigation to AJAX Applications
This article was result of my experience in developing Rich Internet application. It is depiction of my fight against the pitfalls of AJAX application. User is happy if you give him a better usability and performance but he is not aware about the underline technologies. If all of the sudden the default browser navigation stops to work in the desired fashion, user will start to panic. The developer starts getting issues like my back button is not working, clicking refresh lost my work done, so and so forth. The first reaction of developer is this is AJAX world and it act this way only, what can I do? Then we have to look for the ways of supporting default browser navigation in AJAX world. There are few hacks for providing supporting for default browser’s navigation using javascript but AJAX provide more systematic way of doing this. In my article I will explain how to use DOJO history APIs to cope up with one of the pitfall of AJAX application.
To read the article please follow the link
Rounding number in javascript up to some decimal point
If we want to round a number up to certain decimal point, in that case Math.round(x) won’t work . For example if x = 5.67, then Math.round(x) will be 6. In certain cases we want rounding up to some decimal places (y). To do that We need to do the following 1. Multiply given number by 10^y 2. Now round the result using Math.round. e.g. Math.round(x*10^y) 3. Divide number by 10^y. If x = 10.567 and we want to format x up to two points of decimal. We need to do the following
var result = Math.round(x * 100)/100;
And the output will be 10.57
Validating date in Java Script
There are lots of method available which uses REG EXP to validate date and are bit complicated to understand. Here is simple and small date validator.
function isValidDate(day, month, year){
var date;
//Get a Date object based on the given day, month and year
//months start at 0 (0-11 instead of 1-12)
date = new Date(year,month-1,day);
return ((day == date.getDate()) && (month == (date.getMonth()+1))
&& (year == date.getFullYear()));
}
Sun turns JavaScript into Java. Google turns Java into JavaScript
JavaScript is said to be World’s Most Misunderstood Programming Language. Why is the language so misunderstood? It may be the name JavaScript
. It doesn’t have any relation with Java.
No programming language is perfect. JavaScript has many errors like overloading of +, reserved word policies are too rigid, Semicolon insertion and some more.
When I started working on JavaScript, I felt it an easy language but sooner I was facing many issues like browser compatibility, memory leaks and many other common problems.
There are many sites discussing about all these. I would refer few of them in this post.
Being a scripting language, support of object-oriented programming is quite impressive. Even though there are no classes and instances, there are objects, prototypes, and implicit inheritance.
Browser compatibility issue can be handled using object level detection (Don’t check browsers rather check objects).
Memory leak is a challenging problem. The browsers try to work well with broken web, making it look fine and behave well. This is a very difficult task. If browser fails to collect the garbage that we left, is a buggy browser (memory leak). Most browsers don’t do a very good job about memory leak.
I would like to say thanks to Google and many other companies which are writing JavaScript libraries and making JavaScript hot. A good JavaScript Compiler would definitely make JavaScript library implementation easier. Check Google’s web development toolkit.
Mozilla’s (Venkman) JavaScript engine has built-in support for debugging, and thus can provide powerful tools for JavaScript developers.
Check following links
if one closure is buggy, then use more closures
http://www.bazon.net/mishoo/articles.epl?art_id=824
http://talideon.com/weblog/2005/03/js-memory-leaks.cfm
Javascript library
http://www.thingsthemselves.com/~jeff/computing/jslib/
http://www.howtocreate.co.uk/jslibs/
The Event Object
http://www.webdevelopersjournal.com/articles/jsevents3/jsevents3.html
Obejcts
http://developer.mozilla.org/
Google JavaScript APIs
http://code.google.com/apis.html
DISCLAIMER
This Blog includes links to other sites operated by third parties. These links are provided as a convenience to you and as an additional avenue of access to the information contained therein. I have not reviewed all of the information on other sites and are not responsible for the content of any other sites or any products or services that may be offered through other sites. If you are the owner of any of these links and have any objection please do let me know I’ll remove the link.