Friday, October 10, 2008

return key event processing in javascript

function retkey(ev) {

if (ev == null)
ev = window.event;
var key = null;
if (ev.keyCode)
key = ev.keyCode;
else if (ev.which)
key = ev.which;

if (key != null && key == 13)
return ClientValidate();

return true;
}

Thursday, September 25, 2008

Calculating absolute position

// here is a Javascript routine that calculates the absolute position of an html
// element by recursively traversing the parent dom elements
// (works in IE, Firefox, Safari , etc.)

Map.Drawing.Point.prototype.addAbsolutePosition = function(obj) {
var X, Y;
var cur;
if (!obj) {
return this;
}
else
{
X=parseInt("0" + this.x);
Y=parseInt("0" + this.y);
var o = obj;
if (o.offsetParent) //then this object has a container that affects its position
{
while (o.offsetParent)
{
X += parseInt(o.offsetLeft);
Y += parseInt(o.offsetTop);
o = o.offsetParent; //traverse the hierarchy upward
}
}
else if (o.x || o.y) //no container but an absolute position
{
if (o.x) X += parseInt(o.x);
if (o.y) Y += parseInt(o.y);
}

this.x = X;
this.y = Y;

return this;
}
};

Tuesday, September 16, 2008

301 Redirects

To fully retire a page and redirect to a new page SEO (Search Engine Optimization) recommends 301 redirects (as opposed to the regular 303 redirects).

Below is the essential code fragment in Global.asax of the .NET framework to issue a 301 SEO friendly redirect:

// below we are redirecting to www.mynewurl.com
protected void Application_BeginRequest(Object sender, EventArgs e)
{
string oldserver = HttpContext.Current.Request.Url.AbsoluteUri;


// Check whether it is an old url
if (oldserver.IndexOf("myoldurl.com") > -1)
{
HttpContext incoming = HttpContext.Current;

incoming.Response.StatusCode = 301;
incoming.Response.AddHeader("Location", "http://www.mynewurl.com"));
incoming.Response.End();
return;
}

}

// end of 301 redirect logic

In .NET this could better be done with an httpModule. Coding this as an httpModule (instead of in Global.asax) is beyond the scope of this article.

Saturday, August 30, 2008

Search Engine Optimization (SEO)

1- Use the H tages (H1, H2, H3, H4, etc.) tags for important keyword text
- You may repeat your keywords throughout the page (increases density) and bolding and italizing them is also benefitial.
- Keywords at top, but repeat them at bottom. the GO logic is that if something is said at top and repeated at bottom it must be important.
- Use rel="nofollow" on href tags
- All lower case (or same case) file names.
- Do not use "_" in filenames; instead use "-"

Wednesday, January 30, 2008

Optimizing ASP.NET and HTML pages

A comprehensive checklist will serve you well:

- Turn ViewState off on page and control levels when not needed

- Turn SessionState off:
"Session objects consume valuable resources. By turning off sessions, you can improve the performance and scalability of your ASP Web application. You can turn off session state either for the whole Web site or for specific ASP pages."
http://support.microsoft.com/kb/244465

- Alternatives to server controls include simple rendering, HTML elements, inline Response.Write calls, and raw inline angle brackets (<% %>).
(http://msdn2.microsoft.com/en-us/library/ms998549.aspx)

- Especially if not compressing html:
Remove or reduce white space. Removing white spaces can dramatically reduce the size of your pages. Less white space did have about a 5-10K impact on move.com home page when viewed on the browser File-Properties.

-Avoid long control names; especially ones that are repeated in a DataGrid or Repeater control. Control names are used to generate unique HTML ID names. A 10-character control name can easily turn into 30 to 40 characters when it is used inside nested controls that are repeated.

- Use Output caching for user controls , pages, etc. (%@OutputCache directive
)

- Use static properties instead of the Application object to store application state.
(http://msdn2.microsoft.com/en-us/library/ms998549.aspx)


- Use client side validation to avoid unnecessary server hits

-Avoid Creating Deep Hierarchies of Controls (see http://msdn2.microsoft.com/en-us/library/ms998549.aspx#scalenetchapt06_topic11)


Checklist: ASP.NET Performance:
http://msdn2.microsoft.com/en-us/library/ms998596.aspx

Thursday, January 3, 2008

flushing DNS in Windows and MAC OS

Windows:

ipconfig /flushdns


MAC (before Leopard):
sudo lookupd -flushcache

MAC - Leopard:
dscacheutil -flushcache