tag:blogger.com,1999:blog-15566300264942071172024-03-08T06:25:39.261-08:00Wahab WorldYou can find me active at
<a href="http://hellowahab.wordpress.com">http://hellowahab.wordpress.com</a>.Unknownnoreply@blogger.comBlogger61125tag:blogger.com,1999:blog-1556630026494207117.post-40301762043909723302016-05-29T00:19:00.001-07:002016-05-29T00:34:28.238-07:00Focus, an essential ingredient for success <p dir="ltr">In this information age we are overwhelmed with information from different sources like media, Internet etc. <br>
Some time we miss interprete information as knowledge.<br>
Let's say a software engineering student is surfing the Internet and get information a how many languages and tools out there but if he is not focused on one subject he will keep lurking around and would not be able to gain any knowledge about the subject. All he ended up with some information about several topics which he can use during conversation to impress his or her pears with he wouldn't have any real knowledge to use or implements that subject <br>
So always surf the Internet with some concrete subject and try to gain some knowledge instead of random information and this is only possible when you are focused and know your subject </p>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1556630026494207117.post-16753466583988432512016-05-28T00:44:00.001-07:002016-05-28T03:21:01.729-07:00Success in life revolves around deadlines <p dir="ltr">Success in life revolves around setting and achieving deadlines. It is not that deadline which you are bound to complete by your employer. These deadlines are you personal aspirations that you have to achieve be it learning a language be it learning swimming or any personal endeavor. <br>
Usually we all focus around money and tends to focus on task that brings us monetary benefits on high priority. <br>
But only focusing on monetary benefits task will not help you get satisfied and satiated. You have to focus on your personal benefits related task like exercise and some relationship building task. <br>
If you just analyze the life of a normal person he startup as child learning and playing (keeping in view he do not have any financial burden on his shoulder ) Then he chose a profession to earn his bread and butter. And then he continues to work in his profession for the rest of his life <br>
If we divide the life of a person in terms of responsibilities he owes to society we have <br>
An employee or employer <br>
A son or daughter <br>
A sister or brother <br>
A husband or wife <br>
A father or mother <br>
Religious obligation if you follow any religion <br>
National obligation being a citizen of a country <br>
Humanity related obligation towards mankind <br>
There might be other responsibilities you can map with yourself <br>
To be successful you have to have a balance between all your responsibilities <br>
While these all bunch of responsibilities look overwhelming to be fulfilled settings specific deadline can help you be successful <br>
As a child you have to study a whole year to appear in exam so here is the imposed deadline is one year <br>
As a under graduate student you have to study<b> four </b><b>years</b>.<br>
As an employee you have to work a m<b>onth </b>to get a wage <br>
In this competitive world priorities keep changing and sometime you are puzzled what to do or what not to do (and this is the main motive of this post to help you out with this ) over the course of 3.3 decades I have realized that getting engaged in to much things and not completing any is a direct road to be unsuccessful and dissatisfied <br>
So I would suggest one thing. <br>
Always finish w<b><i>hat </i></b><b><i>you </i></b><b><i>start </i></b><br>
And never ever be a chaser of perfection because sometimes people keep thinking about being perfect before actually doing anything and they end up doing nothing <br>
Always remember every master has started as an ama<b>teur </b><br>
<b>If I just keep thinking of the perfect words to write this post neither i written it nor anyone have read this </b><br>
So just to achieve something set a deadline and start working on it. Never ever keep so many things to achieve at a time I suggest focusing on on thing at a time. <br></p>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1556630026494207117.post-33959697870695287972016-05-26T22:09:00.001-07:002016-05-26T22:09:58.393-07:00vpn client not working windows 10<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<b>Installing vpn client on Windows 10 (64 bit):-</b><br />
<br />
Step 1# Install dneupdate 64<br />
<a href="ftp://files.citrix.com/dneupdate64.msi">ftp://files.citrix.com/dneupdate64.msi</a><br />
<br />
Step 2# Install VPN client (if you are reading this blog I think you do have vpn setup alread with you, if not download it here)<br />
<a href="https://software.cisco.com/download/navigator.html?mdfid=270636499&i=rm">https://software.cisco.com/download/navigator.html?mdfid=270636499&i=rm</a><br />
<br />
Step 3#. Open regedit<br />
Browse to the registry key HKLM\SYSTEM\CurrentControlSet\Services\CVirtA<br />
Select the display name to modify:<br />
x86 - "@oem8.ifn,%CVirtA_Desc%;Cisco Systems VPN Adapter" to "Cisco Systems VPN Adapter"<br />
x64 - "@oem8.ifn,%CVirtA_Desc%;Cisco Systems VPN Adapter for 64-bit Windows" to "Cisco Systems VPN Adapter for 64-bit Windows"<br />
<div>
<br /></div>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1556630026494207117.post-50431063782313079952016-05-20T12:14:00.001-07:002016-05-20T12:14:08.779-07:00Tajdar-e-Haram Lyrics<div dir="ltr" style="text-align: left;" trbidi="on">
Lyrics:<br />
قسمت میں مری چین سے جینا لکھ دے<br />
qismat men miri chain se jeena likh de<br />
Let a life of peace and contentment be my fate<br />
ڈوبے نہ کبھی میرا سفینہ لکھ دے<br />
doobe nah kabhi mera safeenah likh de<br />
May my ship never sink even in troubled waters – let this be my fate<br />
جنت بھی گوارا ہے مگر میرے لئے<br />
jannat bhi gawaarah hai magar mere liye<br />
It’s not that heaven would not be acceptable to me, but<br />
اے کاتبِ تقدیر مدینہ لکھ دے<br />
ay kaatib-i taqdeer madeenah likh de<br />
O Writer of Destinies, let Medina be my fate<br />
تاجدارِ حرم<br />
taajdaar-i haram<br />
O king of the holy sanctuary<br />
تاجدارِ حرم ہو نگاہِ کرم<br />
taajdaar-i haram ho nigaah-i karam<br />
O king of the holy sanctuary, bless us with your merciful gaze<br />
تاجدارِ حرم ہو نگاہِ کرم<br />
taajdaar-i haram ho nigaah-i karam<br />
O king of the holy sanctuary, bless us with your merciful gaze<br />
ہم غریبوں کے دن بھی سنور جائیں گے<br />
ham ghareebon ke din bhi sanwar jaaen ge<br />
So that our days of woe may turn for the better<br />
حامیِ بے کساں، کیا کہے گا جہاں<br />
haami-yi be-kasaan kya kahe ga jahaan<br />
O patron of the poor, what would the world say<br />
حامیِ بے کساں، کیا کہے گا جہاں<br />
haami-yi be-kasaan kya kahe ga jahaan<br />
O patron of the poor, what would the world say<br />
آپ کے در سے خالی اگر جائیں گے<br />
aap ke dar se khaali agar jaaen ge<br />
If we return empty-handed from your door?<br />
تاجدارِ حرم<br />
taajdaar-i haram<br />
O king of the holy sanctuary<br />
تاجدارِ حرم<br />
taajdaar-i haram<br />
O king of the holy sanctuary<br />
کوئی اپنا نہیں، غم کے مارے ہیں ہم<br />
koyi apna naheen gham ke maare hain ham<br />
We have no one to call our own, we are stricken with grief<br />
کوئی اپنا نہیں، غم کے مارے ہیں ہم<br />
koyi apna naheen gham ke maare hain ham<br />
We have no one to call our own, we are stricken with grief<br />
آپ کے در پہ فریاد لائے ہیں ہم<br />
aap ke dar pih faryaad laaye hain ham<br />
We come and cry for justice at your door<br />
ہو نگاہِ کرم ورنہ چوکھٹ پہ ہم<br />
ho nigaah-i karam warnah chaukhat pih ham<br />
Please spare us a merciful glance, or we will<br />
ہو نگاہِ کرم ورنہ چوکھٹ پہ ہم<br />
ho nigaah-i karam warnah chaukhat pih ham<br />
Please spare us a merciful glance, or we will<br />
آپ کا نام لے لے کے مر جائیں گے<br />
aap ka naam le le ke mar jaaen ge<br />
Die at your threshold, crying your name<br />
تاجدارِ حرم<br />
taajdaar-i haram<br />
O king of the holy sanctuary<br />
تاجدارِ حرم<br />
taajdaar-i haram<br />
O king of the holy sanctuary<br />
کیا تم سے کہوں اے عرب کے کنور<br />
kya tum se kahoon ay ‘arab ke kunwar<br />
What should I tell you, O Prince of Arabia<br />
تم جانتے ہو من کی بتیاں<br />
tum jaante ho man ki batiyaan<br />
You already know what is in my heart<br />
در فرقتِ تو اے امّی لقب<br />
dar furqat-i to ay ummi-laqab<br />
In your separation, O you who bear the title of the Untaught One<br />
کاٹے نہ کٹے ہیں اب رتیاں<br />
kaate nah kate hain ab ratiyaan<br />
Our sleepless nights are so hard to bear<br />
توری پریت میں سدھ بدھ سب بسری<br />
tori preet men sudh-budh sab bisri<br />
In your love, I have lost all sense of consciousness<br />
کب تک یہ رہیگی بے خبری<br />
kab tak yih rahegi be-khabari<br />
How long will I remain in this state of unconsciousness?<br />
گاہے بفگن دزدیدہ نظر<br />
(کبھی ہمیں دزدیدہ نظر سے دیکھو)<br />
gaahe ba-figan duzdeedah nazar<br />
Cast a stolen glance towards me sometime<br />
کبھی سن بھی تو لو ہمری بتیاں<br />
kabhi sun bhi to lo hamri batiyaan<br />
Turn your ear to my words sometime<br />
آپ کے در سے کوئی نہ خالی گیا<br />
aap ke dar se koyi nah khaali gaya<br />
No one has ever returned empty-handed from your door<br />
آپ کے در سے کوئی نہ خالی گیا<br />
aap ke dar se koyi nah khaali gaya<br />
No one has ever returned empty-handed from your door<br />
آپ کے در سے کوئی نہ خالی گیا<br />
aap ke dar se koyi nah khaali gaya<br />
No one has ever returned empty-handed from your door<br />
اپنے دامن کو بھر کے سوالی گیا<br />
apne daaman ko bhar ke sawaali gaya<br />
Each seeker has returned with his desires fulfilled<br />
اپنے دامن کو بھر کے سوالی گیا<br />
apne daaman ko bhar ke sawaali gaya<br />
Each seeker has returned with his desires fulfilled<br />
ہو حبیبِ حزیں…<br />
ho habeeb-i hazeen<br />
For your sorrowful lover…<br />
ہو حبیبِ حزیں پر بھی آقا نظر<br />
ho habeeb-i hazeen par bhi aaqa nazar<br />
O master, please spare a glance for your sorrowful lover<br />
ورنہ اوراقِ ہستی بکھر جائیں گے<br />
warnah auraaq-i hasti bikhar jaaen ge<br />
Else the pages of existence will become disarrayed<br />
ہو حبیبِ حزیں پر بھی آقا نظر<br />
ho habeeb-i hazeen par bhi aaqa nazar<br />
O master, please spare a glance for your sorrowful lover<br />
ورنہ اوراقِ ہستی بکھر جائیں گے<br />
warnah auraaq-i hasti bikhar jaaen ge<br />
Else the pages of existence will become disarrayed<br />
تاجدارِ حرم<br />
taajdaar-i haram<br />
O king of the holy sanctuary<br />
تاجدارِ حرم<br />
taajdaar-i haram<br />
O king of the holy sanctuary<br />
مے کشو آؤ آؤ مدینے چلیں<br />
mai-kasho aao aao madeene chalen<br />
Come, worshipful wine-drinkers, let’s go to Medina!<br />
مدینے چلیں<br />
madeene chalen<br />
Let’s go to Medina!<br />
مدینے چلیں<br />
madeene chalen<br />
Let’s go to Medina!<br />
مدینے چلیں<br />
madeene chalen<br />
Let’s go to Medina!<br />
مے کشو آؤ آؤ مدینے چلیں<br />
mai-kasho aao aao madeene chalen<br />
Come, worshipful wine-drinkers, let’s go to Medina!<br />
مدینے چلیں<br />
madeene chalen<br />
Let’s go to Medina!<br />
مدینے چلیں<br />
madeene chalen<br />
Let’s go to Medina!<br />
مدینے چلیں<br />
madeene chalen<br />
Let’s go to Medina!<br />
آؤ مدینے چلیں<br />
aao madeene chalen<br />
Come, let’s go to Medina!<br />
آؤ مدینے چلیں<br />
aao madeene chalen<br />
Come, let’s go to Medina!<br />
اسی مہینے چلیں<br />
isi maheene chalen<br />
Let’s go this very month<br />
آؤ مدینے چلیں<br />
aao madeene chalen<br />
Come, let’s go to Medina!<br />
آؤ مدینے چلیں<br />
aao madeene chalen<br />
Come, let’s go to Medina!<br />
آؤ مدینے چلیں<br />
aao madeene chalen<br />
Come, let’s go to Medina!<br />
اسی مہینے چلیں<br />
isi maheene chalen<br />
Let’s go this very month<br />
آؤ مدینے چلیں<br />
aao madeene chalen<br />
Come, let’s go to Medina!<br />
تجلّیوں کی عجب ہے فضا مدینے میں<br />
tajalliyon ki ‘ajab hai faza madeene men<br />
The wonders of His Glory are glitteringly manifest in Medina<br />
تجلّیوں کی عجب ہے فضا مدینے میں<br />
tajalliyon ki ‘ajab hai faza madeene men<br />
The wonders of His Glory are glitteringly manifest in Medina<br />
نگاہِ شوق کی ہے انتہا مدینے میں<br />
nigaah-i shauq ki hai intiha madeene men<br />
The ardent gaze knows boundless fulfilment in Medina<br />
نگاہِ شوق کی ہے انتہا مدینے میں<br />
nigaah-i shauq ki hai intiha madeene men<br />
The ardent gaze knows boundless fulfilment in Medina<br />
غمِ حیات نہ خوفِ قضا مدینے میں<br />
gham-i hayaat nah khauf-i qaza madeene men<br />
There’s neither sorrow of life nor fear of death in Medina<br />
غمِ حیات نہ خوفِ قضا مدینے میں<br />
gham-i hayaat nah khauf-i qaza madeene men<br />
There’s neither sorrow of life nor fear of death in Medina<br />
نمازِ عشق کریں گے ادا مدینے میں<br />
namaaz-i ‘ishq karen ge ada madeene men<br />
We will perform the prayer of Love in Medina<br />
نمازِ عشق کریں گے ادا مدینے میں<br />
namaaz-i ‘ishq karen ge ada madeene men<br />
We will perform the prayer of Love in Medina<br />
براہِ راست ہے راہِ خدا مدینے میں<br />
ba-raah-i raast hai raah-i khuda madeene men<br />
Clear and direct is the path to God in Medina<br />
آؤ مدینے چلیں<br />
aao madeene chalen<br />
Let’s go to Medina!<br />
اسی مہینے چلیں<br />
isi maheene chalen<br />
Let’s go this very month<br />
آؤ مدینے چلیں<br />
aao madeene chalen<br />
Come, let’s go to Medina!<br />
مے کشو آؤ آؤ مدینے چلیں<br />
mai-kasho aao aao madeene chalen<br />
Come, worshipful wine-drinkers, let’s go to Medina!<br />
مے کشو آؤ آؤ مدینے چلیں<br />
mai-kasho aao aao madeene chalen<br />
Come, worshipful wine-drinkers, let’s go to Medina!<br />
دستِ ثاقیِ کوثر سے پینے چلیں<br />
dast-i saaqi-yi kausar se peene chalen<br />
Let’s go and drink from the hand of the Cupbearer of Kausar<br />
دستِ ثاقیِ کوثر سے پینے چلیں<br />
dast-i saaqi-yi kausar se peene chalen<br />
Let’s go and drink from the hand of the Cupbearer of Kausar<br />
یاد رکھو اگر…<br />
yaad rakkho agar<br />
Keep in mind that…<br />
یاد رکھو اگر…<br />
yaad rakkho agar<br />
Keep in mind that…<br />
یاد رکھو اگر…<br />
yaad rakkho agar<br />
Keep in mind that…<br />
یاد رکھو اگر…<br />
yaad rakkho agar<br />
Keep in mind that…<br />
گئی اک نظر اٹھ<br />
uth gayi ik nazar<br />
If he looks up but once<br />
جتنے خالی ہیں سب جام بھر جائیں گے<br />
jitne khaali hain sab jaam bhar jaaen ge<br />
All the wine-cups that are empty will become filled!<br />
یاد رکھو اگر اٹھ گئی اک نظر<br />
yaad rakkho agar uth gayi ik nazar<br />
Keep in mind that if he looks up but once<br />
وہ نظر<br />
wuh nazar<br />
A look from him!<br />
جتنے خالی ہیں سب جام بھر جائیں گے<br />
jitne khaali hain sab jaam bhar jaaen ge<br />
All the wine-cups that are empty will become filled!<br />
تاجدارِ حرم<br />
taajdaar-i haram<br />
O king of the holy sanctuary<br />
تاجدارِ حرم<br />
taajdaar-i haram<br />
O king of the holy sanctuary<br />
خوفِ طوفان ہے بجلیوں کا ہے ڈر<br />
khauf-i toofaan hai bijliyon ka hai dar<br />
There is fear of the storm, and dread of lightning<br />
خوفِ طوفان ہے بجلیوں کا ہے ڈر<br />
khauf-i toofaan hai bijliyon ka hai dar<br />
There is fear of the storm, and dread of lightning<br />
سخت مشکل ہے آقا کدھر جائیں ہم<br />
sakht mushkil hai aaqa kidhar jaaen ham<br />
Our distress is severe, master, to whom should we turn?<br />
سخت مشکل ہے آقا کدھر جائیں ہم<br />
sakht mushkil hai aaqa kidhar jaaen ham<br />
Our distress is severe, master, to whom should we turn?<br />
آپ ہی گر نہ لیں گے ہماری خبر<br />
aap hi gar nah len ge hamaari khabar<br />
If you would not trouble to see how we fare<br />
ہم مصیبت کے مارے کدھر جائیں گے<br />
ham museebat ke maare kidhar jaaen ge<br />
Our afflictions would surely kill us<br />
آپ ہی گر نہ لیں گے ہماری خبر<br />
aap hi gar nah len ge hamaari khabar<br />
If you would not trouble to see how we fare<br />
ہم مصیبت کے مارے کدھر جائیں گے<br />
ham museebat ke maare kidhar jaaen ge<br />
Our afflictions would surely kill us<br />
تاجدارِ حرم<br />
taajdaar-i haram<br />
O king of the holy sanctuary<br />
تاجدارِ حرم<br />
taajdaar-i haram<br />
O king of the holy sanctuary<br />
یا مصطفیٰ یا مجتبیٰ، اِرحم لنا اِرحم لنا<br />
(یا مصطفیٰ یا مجتبیٰ، ہم پر رحم کر، ہم پر رحم کر)<br />
ya mustafa ya mujtaba irham lana irham lana<br />
O Mustafa, O Mujtaba, show us mercy<br />
دستِ ہمہ بیچارہ را داماں توئی داماں توئی<br />
(جس کو تمام بے چارہ اور بے سہارا لوگ تھامتے ہیں، تو وہ دامن ہے)<br />
dast-i hamah be-chaara ra, daamaan to-yi, daamaan to-yi<br />
Yours is the hand all the helpless and hopeless grasp<br />
من عاصیم من عاجزم من بے کسم، حالِ مرا<br />
(میں عاصی ہوں، میں عاجز ہوں، میں بیکس ہوں، میرے حال کا)<br />
man ‘aasi-yam man ‘aajiz-am man be-kas-am haal-i mara<br />
I am a sinner, feeble and helpless, friendless and destitute, and you<br />
پرساں توئی پرساں توئی<br />
(تو ہی پرساں ہے)<br />
pursaan to-yi pursaan to-yi<br />
Are the only one who cares for me<br />
اے مشک بید عنبر فشاں<br />
ay mushk-bed ‘ambar-fishaan<br />
O musk-willow, scattering fragrance<br />
پیکِ نسیمِ صبح دم<br />
paik-i naseem-i subh-dam<br />
O sweet breeze of the early morn<br />
اے چارہ گر عیسیٰ نفس<br />
ay chaarah-gar ‘eesa-nafas<br />
O you who cures ills, O you with the breath of Jesus<br />
اے مونسِ بیمارِ غم<br />
ay moonis-i beemaar-i gham<br />
O consoler of the grief-stricken<br />
اے قاسدِ فرخندہ پہ<br />
ay qaasid-i farkhundah pah<br />
O auspicious messenger<br />
تجھ کو اُسی گل کی قسم<br />
tujh ko usi gul ki qasam<br />
I beg you in the name of that same fragrance<br />
إن نلت يا ريح الصّبا<br />
(اے بادِ صبا، اگر تیرا گزر)<br />
in nalti ya reeh as-saba<br />
O morning breeze, if you pass<br />
يوماً إلى أرض الحرم<br />
(کسی روز اس مقدس سرزمین سے ہو)<br />
yauman ila ard il-haram<br />
If you pass by that sacred land someday<br />
بلّغ سلامي روضةً<br />
( تو پہنچانا میرا سلام اس روضے پر)<br />
balligh salaami raudatan<br />
Present my greetings at the blessed grave<br />
فيها النّبي المحترم<br />
(جس میں ہیں نبیِ محترم)<br />
feeh an-nabi yul-mohtaram<br />
Where the revered Prophet rests<br />
تاجدارِ حرم ہو نگاہِ کرم<br />
taajdaar-i haram ho nigaah-i karam<br />
O king of the holy sanctuary, bless us with your merciful gaze<br />
تاجدارِ حرم ہو نگاہِ کرم<br />
taajdaar-i haram ho nigaah-i karam<br />
O king of the holy sanctuary, bless us with your merciful gaze<br />
ہم غریبوں کے دن بھی سنور جائیں گے<br />
ham ghareebon ke din bhi sanwar jaaen ge<br />
So that our days of woe may turn for the better<br />
حامیِ بے کساں، کیا کہے گا جہاں<br />
haami-yi be-kasaan kya kahe ga jahaan<br />
O patron of the poor, what would the world say<br />
حامیِ بے کساں، کیا کہے گا جہاں<br />
haami-yi be-kasaan kya kahe ga jahaan<br />
O patron of the poor, what would the world say<br />
آپ کے در سے خالی اگر جائیں گے<br />
aap ke dar se khaali agar jaaen ge<br />
If we return empty-handed from your door?<br />
تاجدارِ حرم<br />
taajdaar-i haram<br />
O king of the holy sanctuary<br />
تاجدارِ حرم<br />
taajdaar-i haram<br />
O king of the holy sanctuary<br />
تاجدارِ حرم<br />
taajdaar-i haram<br />
O king of the holy sanctuary</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1556630026494207117.post-60353735169699203002016-05-16T21:35:00.001-07:002016-05-16T21:35:57.825-07:00Always finish what you start <p dir="ltr">If you in the habit of not completing what you start you are on a straight path to get failed. <br>
No matter how smart or dumb you are get into the habit of completing what you start and you will see the difference. <br>
Not only you have more completed stuff at your hands you will also have more sense of achievement. <br>
This will also grow you in terms of selecting what to do or what not to do </p>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1556630026494207117.post-51411150592715966982016-05-16T21:26:00.001-07:002016-05-16T21:26:10.345-07:00You can never be perfect without starting immature <p dir="ltr">We always aim and strive to be perfect and sometime feel embraced and ashamed of trying something new just because people will perceive us as immature. <br>
This nature and thinking of us is a killer for our improvement as an individual. <br>
Be it blog writing. <br>
Be it playing cricket <br>
Be it anything else. <br>
Always remember that to be perfect you have to start immature so never ever get afraid of trying something new <br>
</p>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1556630026494207117.post-28718741714769875562016-05-16T21:03:00.001-07:002016-05-16T21:03:16.655-07:00Integrating git projects on cruise control <p dir="ltr">To be posted soon. If you need help on this let me know l will prioritize this first </p>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1556630026494207117.post-65105818214216943812016-05-16T21:01:00.001-07:002016-05-16T21:01:01.616-07:00My programming aspirations <p dir="ltr">Following is the list of languages technologies I know and wishes to learn more about in order of priority <br>
1. C #<br>
2. Java <br>
3. Node js <br>
4. Algorithms<br>
5 programming competition <br>
6. Iot <br>
7......... I will keep this list getting updated as time passes <br>
</p>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1556630026494207117.post-69245559858877264322016-05-16T20:48:00.001-07:002016-05-16T20:48:48.017-07:00My programming journey <p dir="ltr">It's been more than ten years I am working in the software development field. Despite my knowledge I feel my knowledge sharing is way too less. I will try to make these posts beneficial for all programmers </p>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1556630026494207117.post-56088232587908444512011-01-26T22:21:00.000-08:002011-01-26T22:28:29.884-08:00Eclipse: how to open an existing project in Eclipse for Visual Studio Developers<div dir="ltr" style="text-align: left;" trbidi="on"><div class="content clear-block" style="text-align: justify;">So here are the instructions on opening existing projects into Eclipse.<br />
If you are a Visual Studio developer you are here because you can't open an existing project in Eclipse. You are probably 5 minutes away from giving up on eclipse and tweeting about how Eclipse sucks.<br />
I was there too.<br />
And then, after attempting it again and again, I finally figured it out. I am going to translate opening an existing project from Eclipse into Visual Studio here. Think about these two IDEs as cars: Visual Studio is an automatic, eclipse is manual transmission.<br />
There are two things you got to know:<br />
A) <b>Workspace = Solution</b><br />
B) <b>You got to set it by hand</b><br />
I normally don't think about the solution because Visual Studio lovingly just creates one for me. If I need to add projects to it, it can be done easily. It makes me happy; it has made you happy too. When it comes to creating solution and project spaces, Visual Studio is like an automatic car: it just does it for you.<br />
But in eclipse you got to do it by hand. Maybe there is a plugin that will make it behave like Visual Studio, but in most distributions you will have to do it manually. It is not hard, but you got to do it. On this issue, eclipse is like a manual transmission car: you got to know and be aware of different gears and when to switch them.<br />
So let's learn how to drive stick by learning how to set up your workspace/solution and how to add existing projects to it:<br />
<b>Create a new workspace by clicking<br />
File -> Switch Workspaces -> Other</b><br />
Browse to where you want your workspace (solution) folder to live in, where you have the existing project folder. This is the equivalent of Add Project in Visual Studio.<br />
<b>Add a project to the workspace by clicking<br />
File-> Import-> General-> Import Existing Projects into Workspace</b><br />
And navigate to the existing project root folder.<br />
And you are done.<br />
Now let's learn how to switch gears. In Visual Studio you will have your landing page with a list of previous projects. When you click on the project, the solution automatically switches. That is our automatic car. With our stick vehicle, to switch from one workspace(solution) to another you do it by clicking<br />
<b>File -> Switch Workspaces -> >>Select workspace that you want to go to<<</b><br />
Remember, you got to manually change the workspace(solution). Attempting to switch solutions in the Visual Studio way, that is, by "opening" another project via project import, will result into adding that project into the workspace, not into an automatic workspace switch.<br />
References:<br />
I found the specific instructions on how to open an existing project on this book <a href="https://epoch.oreilly.com/shop/cart.orm?prod=9780596521479.BOOK&p=SFCPMAX">Android Application Development, 1st. Edition</a><br />
<br />
NOTE:- ABOVE MENTIONED ARTICLE IS COPIED FROM <br />
<a href="http://www.hugoestrada.net/node/121">http://www.hugoestrada.net/node/121</a><br />
<br />
</div></div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1556630026494207117.post-48313782260268044502011-01-19T03:13:00.000-08:002011-01-19T03:12:06.539-08:00Best open source project<div class=Section1> <p class=MsoNormal>In my opinion following are the best open source project:-<o:p></o:p></p> <p class=MsoListParagraph style='text-indent:-.25in;mso-list:l0 level1 lfo1'><![if !supportLists]><span style='mso-list:Ignore'>1.<span style='font:7.0pt "Times New Roman"'> </span></span><![endif]>Blogs<o:p></o:p></p> <p class=MsoListParagraph style='margin-left:1.0in;text-indent:-.25in; mso-list:l0 level2 lfo1'><![if !supportLists]><span style='mso-list:Ignore'>a.<span style='font:7.0pt "Times New Roman"'> </span></span><![endif]><a href="http://www.dotnetblogengine.net/">BlogEngine.NET</a> (Asp.net)<o:p></o:p></p> <p class=MsoListParagraph style='text-indent:-.25in;mso-list:l0 level1 lfo1'><![if !supportLists]><span style='mso-list:Ignore'>2.<span style='font:7.0pt "Times New Roman"'> </span></span><![endif]>eCommerce<o:p></o:p></p> <p class=MsoListParagraph style='margin-left:1.0in;text-indent:-.25in; mso-list:l0 level2 lfo1'><![if !supportLists]><span style='mso-list:Ignore'>a.<span style='font:7.0pt "Times New Roman"'> </span></span><![endif]><a href="http://www.nopcommerce.com/default.aspx">nopCommerce</a><o:p></o:p></p> <p class=MsoListParagraph style='text-indent:-.25in;mso-list:l0 level1 lfo1'><![if !supportLists]><span style='mso-list:Ignore'>3.<span style='font:7.0pt "Times New Roman"'> </span></span><![endif]>Image Gallery<o:p></o:p></p> <p class=MsoListParagraph style='margin-left:1.0in;text-indent:-.25in; mso-list:l0 level2 lfo1'><![if !supportLists]><span style='mso-list:Ignore'>a.<span style='font:7.0pt "Times New Roman"'> </span></span><![endif]><a href="http://www.galleryserverpro.com/">GalleryServerPro</a><o:p></o:p></p> <p class=MsoListParagraph style='text-indent:-.25in;mso-list:l0 level1 lfo1'><![if !supportLists]><span style='mso-list:Ignore'>4.<span style='font:7.0pt "Times New Roman"'> </span></span><![endif]>CRM<o:p></o:p></p> <p class=MsoListParagraph style='margin-left:1.0in;text-indent:-.25in; mso-list:l0 level2 lfo1'><![if !supportLists]><span style='mso-list:Ignore'>a.<span style='font:7.0pt "Times New Roman"'> </span></span><![endif]><a href="http://www.splendidcrm.com/">SplendidCRM</a><o:p></o:p></p> </div> Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1556630026494207117.post-49650898971947908032011-01-11T22:39:00.000-08:002011-01-11T22:46:37.364-08:00Detailed Asp.net Page life Exposed<p class="mobile-photo"><a href="http://4.bp.blogspot.com/_abnRxXonUqU/TS1OTfX72_I/AAAAAAAAALQ/fhitvRybGK0/s1600/IC386473-797368.png"><img src="http://4.bp.blogspot.com/_abnRxXonUqU/TS1OTfX72_I/AAAAAAAAALQ/fhitvRybGK0/s320/IC386473-797368.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5561187211618802674" /></a></p><div class=Section1> <p class=MsoNormal><o:p> </o:p></p> </div> Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1556630026494207117.post-67593259327008379372010-08-18T22:43:00.000-07:002010-08-18T22:44:36.800-07:00Javascript Validation<div class=Section1> <p class=MsoNormal>This is an impressive collection (that I found somehere on the Net) of various functions to validate or format string in Javascript. The code is very compact. <o:p></o:p></p> <pre>/****************************************************************<o:p></o:p></pre><pre>FILE: RegExpValidate.js<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>DESCRIPTION: This file contains a library of validation functions<o:p></o:p></pre><pre> using javascript regular expressions. Library also contains <o:p></o:p></pre><pre> functions that reformat fields for display or for storage.<o:p></o:p></pre><pre><o:p> </o:p></pre><pre><o:p> </o:p></pre><pre> VALIDATION FUNCTIONS:<o:p></o:p></pre><pre><o:p> </o:p></pre><pre> validateEmail - checks format of email address<o:p></o:p></pre><pre> validateUSPhone - checks format of US phone number<o:p></o:p></pre><pre> validateNumeric - checks for valid numeric value<o:p></o:p></pre><pre> validateInteger - checks for valid integer value<o:p></o:p></pre><pre> validateNotEmpty - checks for blank form field<o:p></o:p></pre><pre> validateUSZip - checks for valid US zip code<o:p></o:p></pre><pre> validateUSDate - checks for valid date in US format<o:p></o:p></pre><pre> validateValue - checks a string against supplied pattern<o:p></o:p></pre><pre><o:p> </o:p></pre><pre> FORMAT FUNCTIONS:<o:p></o:p></pre><pre><o:p> </o:p></pre><pre> rightTrim - removes trailing spaces from a string<o:p></o:p></pre><pre> leftTrim - removes leading spaces from a string<o:p></o:p></pre><pre> trimAll - removes leading and trailing spaces from a string<o:p></o:p></pre><pre> removeCurrency - removes currency formatting characters (), $<o:p></o:p></pre><pre> addCurrency - inserts currency formatting characters<o:p></o:p></pre><pre> removeCommas - removes comma separators from a number<o:p></o:p></pre><pre> addCommas - adds comma separators to a number<o:p></o:p></pre><pre> removeCharacters - removes characters from a string that match <o:p></o:p></pre><pre> passed pattern<o:p></o:p></pre><pre><o:p> </o:p></pre><pre><o:p> </o:p></pre><pre>AUTHOR: Karen Gayda<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>DATE: 03/24/2000<o:p></o:p></pre><pre>*******************************************************************/<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>function validateEmail( strValue) {<o:p></o:p></pre><pre>/************************************************<o:p></o:p></pre><pre>DESCRIPTION: Validates that a string contains a<o:p></o:p></pre><pre> valid email pattern.<o:p></o:p></pre><pre><o:p> </o:p></pre><pre> PARAMETERS:<o:p></o:p></pre><pre> strValue - String to be tested for validity<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>RETURNS:<o:p></o:p></pre><pre> True if valid, otherwise false.<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>REMARKS: Accounts for email with country appended<o:p></o:p></pre><pre> does not validate that email contains valid URL<o:p></o:p></pre><pre> type (.com, .gov, etc.) or valid country suffix.<o:p></o:p></pre><pre><span lang=ES-UY>*************************************************/<o:p></o:p></span></pre><pre><span lang=ES-UY>var objRegExp =<o:p></o:p></span></pre><pre><span lang=ES-UY> /(^[a-z]([a-z_\.]*)@([a-z_\.]*)([.][a-z]{3})$)|(^[a-z]([a-z_\.]*)@<o:p></o:p></span></pre><pre><span lang=ES-UY> </span>([a-z_\.]*)(\.[a-z]{3})(\.[a-z]{2})*$)/i;<o:p></o:p></pre><pre><o:p> </o:p></pre><pre> //check for valid email<o:p></o:p></pre><pre> return objRegExp.test(strValue);<o:p></o:p></pre><pre>}<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>function validateUSPhone( strValue ) {<o:p></o:p></pre><pre>/************************************************<o:p></o:p></pre><pre>DESCRIPTION: Validates that a string contains valid<o:p></o:p></pre><pre> US phone pattern.<o:p></o:p></pre><pre> Ex. (999) 999-9999 or (999)999-9999<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>PARAMETERS:<o:p></o:p></pre><pre> strValue - String to be tested for validity<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>RETURNS:<o:p></o:p></pre><pre> True if valid, otherwise false.<o:p></o:p></pre><pre>*************************************************/<o:p></o:p></pre><pre> var objRegExp = /^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/;<o:p></o:p></pre><pre><o:p> </o:p></pre><pre> //check for valid us phone with or without space between<o:p></o:p></pre><pre> //area code<o:p></o:p></pre><pre> return objRegExp.test(strValue);<o:p></o:p></pre><pre>}<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>function validateNumeric( strValue ) {<o:p></o:p></pre><pre>/*****************************************************************<o:p></o:p></pre><pre>DESCRIPTION: Validates that a string contains only valid numbers.<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>PARAMETERS:<o:p></o:p></pre><pre> strValue - String to be tested for validity<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>RETURNS:<o:p></o:p></pre><pre> True if valid, otherwise false.<o:p></o:p></pre><pre><span lang=ES-UY>******************************************************************/<o:p></o:p></span></pre><pre><span lang=ES-UY> var objRegExp = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;<o:p></o:p></span></pre><pre><span lang=ES-UY><o:p> </o:p></span></pre><pre><span lang=ES-UY> </span>//check for numeric characters<o:p></o:p></pre><pre> return objRegExp.test(strValue);<o:p></o:p></pre><pre>}<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>function validateInteger( strValue ) {<o:p></o:p></pre><pre>/************************************************<o:p></o:p></pre><pre>DESCRIPTION: Validates that a string contains only<o:p></o:p></pre><pre> valid integer number.<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>PARAMETERS:<o:p></o:p></pre><pre> strValue - String to be tested for validity<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>RETURNS:<o:p></o:p></pre><pre> True if valid, otherwise false.<o:p></o:p></pre><pre>**************************************************/<o:p></o:p></pre><pre> var objRegExp = /(^-?\d\d*$)/;<o:p></o:p></pre><pre><o:p> </o:p></pre><pre> //check for integer characters<o:p></o:p></pre><pre> return objRegExp.test(strValue);<o:p></o:p></pre><pre>}<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>function validateNotEmpty( strValue ) {<o:p></o:p></pre><pre>/************************************************<o:p></o:p></pre><pre>DESCRIPTION: Validates that a string is not all<o:p></o:p></pre><pre> blank (whitespace) characters.<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>PARAMETERS:<o:p></o:p></pre><pre> strValue - String to be tested for validity<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>RETURNS:<o:p></o:p></pre><pre> True if valid, otherwise false.<o:p></o:p></pre><pre>*************************************************/<o:p></o:p></pre><pre> var strTemp = strValue;<o:p></o:p></pre><pre> strTemp = trimAll(strTemp);<o:p></o:p></pre><pre> if(strTemp.length > 0){<o:p></o:p></pre><pre> return true;<o:p></o:p></pre><pre> }<o:p></o:p></pre><pre> return false;<o:p></o:p></pre><pre>}<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>function validateUSZip( strValue ) {<o:p></o:p></pre><pre>/************************************************<o:p></o:p></pre><pre>DESCRIPTION: Validates that a string a United<o:p></o:p></pre><pre> States zip code in 5 digit format or zip+4<o:p></o:p></pre><pre> format. 99999 or 99999-9999<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>PARAMETERS:<o:p></o:p></pre><pre> strValue - String to be tested for validity<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>RETURNS:<o:p></o:p></pre><pre> True if valid, otherwise false.<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>*************************************************/<o:p></o:p></pre><pre>var objRegExp = /(^\d{5}$)|(^\d{5}-\d{4}$)/;<o:p></o:p></pre><pre><o:p> </o:p></pre><pre> //check for valid US Zipcode<o:p></o:p></pre><pre> return objRegExp.test(strValue);<o:p></o:p></pre><pre>}<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>function validateUSDate( strValue ) {<o:p></o:p></pre><pre>/************************************************<o:p></o:p></pre><pre>DESCRIPTION: Validates that a string contains only<o:p></o:p></pre><pre> valid dates with 2 digit month, 2 digit day,<o:p></o:p></pre><pre> 4 digit year. Date separator can be ., -, or /.<o:p></o:p></pre><pre> Uses combination of regular expressions and<o:p></o:p></pre><pre> string parsing to validate date.<o:p></o:p></pre><pre> Ex. mm/dd/yyyy or mm-dd-yyyy or mm.dd.yyyy<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>PARAMETERS:<o:p></o:p></pre><pre> strValue - String to be tested for validity<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>RETURNS:<o:p></o:p></pre><pre> True if valid, otherwise false.<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>REMARKS:<o:p></o:p></pre><pre> Avoids some of the limitations of the Date.parse()<o:p></o:p></pre><pre> method such as the date separator character.<o:p></o:p></pre><pre>*************************************************/<o:p></o:p></pre><pre> var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/<o:p></o:p></pre><pre> <o:p></o:p></pre><pre> //check to see if in correct format<o:p></o:p></pre><pre> if(!objRegExp.test(strValue))<o:p></o:p></pre><pre> return false; //doesn't match pattern, bad date<o:p></o:p></pre><pre> else{<o:p></o:p></pre><pre> var strSeparator = strValue.substring(2,3) <o:p></o:p></pre><pre> var arrayDate = strValue.split(strSeparator); <o:p></o:p></pre><pre> //create a lookup for months not equal to Feb.<o:p></o:p></pre><pre> var arrayLookup = { '01' : 31,'03' : 31, <o:p></o:p></pre><pre> '04' : 30,'05' : 31,<o:p></o:p></pre><pre> '06' : 30,'07' : 31,<o:p></o:p></pre><pre> '08' : 31,'09' : 30,<o:p></o:p></pre><pre> '10' : 31,'11' : 30,'12' : 31}<o:p></o:p></pre><pre> var intDay = parseInt(arrayDate[1],10); <o:p></o:p></pre><pre><o:p> </o:p></pre><pre> //check if month value and day value agree<o:p></o:p></pre><pre> if(arrayLookup[arrayDate[0]] != null) {<o:p></o:p></pre><pre> if(intDay <= arrayLookup[arrayDate[0]] && intDay != 0)<o:p></o:p></pre><pre> return true; //found in lookup table, good date<o:p></o:p></pre><pre> }<o:p></o:p></pre><pre> <o:p></o:p></pre><pre> //check for February (bugfix 20050322)<o:p></o:p></pre><pre> //bugfix for parseInt kevin<o:p></o:p></pre><pre> //bugfix biss year O.Jp Voutat<o:p></o:p></pre><pre> var intMonth = parseInt(arrayDate[0],10);<o:p></o:p></pre><pre> if (intMonth == 2) { <o:p></o:p></pre><pre> var intYear = parseInt(arrayDate[2]);<o:p></o:p></pre><pre> if (intDay > 0 && intDay < 29) {<o:p></o:p></pre><pre> return true;<o:p></o:p></pre><pre> }<o:p></o:p></pre><pre> else if (intDay == 29) {<o:p></o:p></pre><pre> if ((intYear % 4 == 0) && (intYear % 100 != 0) || <o:p></o:p></pre><pre> (intYear % 400 == 0)) {<o:p></o:p></pre><pre> // year div by 4 and ((not div by 100) or div by 400) ->ok<o:p></o:p></pre><pre> return true;<o:p></o:p></pre><pre> } <o:p></o:p></pre><pre> }<o:p></o:p></pre><pre> }<o:p></o:p></pre><pre> } <o:p></o:p></pre><pre> return false; //any other values, bad date<o:p></o:p></pre><pre>}<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>function validateValue( strValue, strMatchPattern ) {<o:p></o:p></pre><pre>/************************************************<o:p></o:p></pre><pre>DESCRIPTION: Validates that a string a matches<o:p></o:p></pre><pre> a valid regular expression value.<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>PARAMETERS:<o:p></o:p></pre><pre> strValue - String to be tested for validity<o:p></o:p></pre><pre> strMatchPattern - String containing a valid<o:p></o:p></pre><pre> regular expression match pattern.<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>RETURNS:<o:p></o:p></pre><pre> True if valid, otherwise false.<o:p></o:p></pre><pre>*************************************************/<o:p></o:p></pre><pre>var objRegExp = new RegExp( strMatchPattern);<o:p></o:p></pre><pre><o:p> </o:p></pre><pre> //check if string matches pattern<o:p></o:p></pre><pre> return objRegExp.test(strValue);<o:p></o:p></pre><pre>}<o:p></o:p></pre><pre><o:p> </o:p></pre><pre><o:p> </o:p></pre><pre>function rightTrim( strValue ) {<o:p></o:p></pre><pre>/************************************************<o:p></o:p></pre><pre>DESCRIPTION: Trims trailing whitespace chars.<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>PARAMETERS:<o:p></o:p></pre><pre> strValue - String to be trimmed.<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>RETURNS:<o:p></o:p></pre><pre> Source string with right whitespaces removed.<o:p></o:p></pre><pre>*************************************************/<o:p></o:p></pre><pre>var objRegExp = /^([\w\W]*)(\b\s*)$/;<o:p></o:p></pre><pre><o:p> </o:p></pre><pre> if(objRegExp.test(strValue)) {<o:p></o:p></pre><pre> //remove trailing a whitespace characters<o:p></o:p></pre><pre> strValue = strValue.replace(objRegExp, '$1');<o:p></o:p></pre><pre> }<o:p></o:p></pre><pre> return strValue;<o:p></o:p></pre><pre>}<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>function leftTrim( strValue ) {<o:p></o:p></pre><pre>/************************************************<o:p></o:p></pre><pre>DESCRIPTION: Trims leading whitespace chars.<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>PARAMETERS:<o:p></o:p></pre><pre> strValue - String to be trimmed<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>RETURNS:<o:p></o:p></pre><pre> Source string with left whitespaces removed.<o:p></o:p></pre><pre>*************************************************/<o:p></o:p></pre><pre>var objRegExp = /^(\s*)(\b[\w\W]*)$/;<o:p></o:p></pre><pre><o:p> </o:p></pre><pre> if(objRegExp.test(strValue)) {<o:p></o:p></pre><pre> //remove leading a whitespace characters<o:p></o:p></pre><pre> strValue = strValue.replace(objRegExp, '$2');<o:p></o:p></pre><pre> }<o:p></o:p></pre><pre> return strValue;<o:p></o:p></pre><pre>}<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>function trimAll( strValue ) {<o:p></o:p></pre><pre>/************************************************<o:p></o:p></pre><pre>DESCRIPTION: Removes leading and trailing spaces.<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>PARAMETERS: Source string from which spaces will<o:p></o:p></pre><pre> be removed;<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>RETURNS: Source string with whitespaces removed.<o:p></o:p></pre><pre>*************************************************/<o:p></o:p></pre><pre> var objRegExp = /^(\s*)$/;<o:p></o:p></pre><pre><o:p> </o:p></pre><pre> //check for all spaces<o:p></o:p></pre><pre> if(objRegExp.test(strValue)) {<o:p></o:p></pre><pre> strValue = strValue.replace(objRegExp, '');<o:p></o:p></pre><pre> if( strValue.length == 0)<o:p></o:p></pre><pre> return strValue;<o:p></o:p></pre><pre> }<o:p></o:p></pre><pre><o:p> </o:p></pre><pre> //check for leading & trailing spaces<o:p></o:p></pre><pre> objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;<o:p></o:p></pre><pre> if(objRegExp.test(strValue)) {<o:p></o:p></pre><pre> //remove leading and trailing whitespace characters<o:p></o:p></pre><pre> strValue = strValue.replace(objRegExp, '$2');<o:p></o:p></pre><pre> }<o:p></o:p></pre><pre> return strValue;<o:p></o:p></pre><pre>}<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>function removeCurrency( strValue ) {<o:p></o:p></pre><pre>/************************************************<o:p></o:p></pre><pre>DESCRIPTION: Removes currency formatting from<o:p></o:p></pre><pre> source string.<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>PARAMETERS:<o:p></o:p></pre><pre> strValue - Source string from which currency formatting<o:p></o:p></pre><pre> will be removed;<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>RETURNS: Source string with commas removed.<o:p></o:p></pre><pre>*************************************************/<o:p></o:p></pre><pre> var objRegExp = /\(/;<o:p></o:p></pre><pre> var strMinus = '';<o:p></o:p></pre><pre><o:p> </o:p></pre><pre> //check if negative<o:p></o:p></pre><pre> if(objRegExp.test(strValue)){<o:p></o:p></pre><pre> strMinus = '-';<o:p></o:p></pre><pre> }<o:p></o:p></pre><pre><o:p> </o:p></pre><pre> objRegExp = /\)|\(|[,]/g;<o:p></o:p></pre><pre> strValue = strValue.replace(objRegExp,'');<o:p></o:p></pre><pre> if(strValue.indexOf('$') >= 0){<o:p></o:p></pre><pre> strValue = strValue.substring(1, strValue.length);<o:p></o:p></pre><pre> }<o:p></o:p></pre><pre> return strMinus + strValue;<o:p></o:p></pre><pre>}<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>function addCurrency( strValue ) {<o:p></o:p></pre><pre>/************************************************<o:p></o:p></pre><pre>DESCRIPTION: Formats a number as currency.<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>PARAMETERS:<o:p></o:p></pre><pre> strValue - Source string to be formatted<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>REMARKS: Assumes number passed is a valid<o:p></o:p></pre><pre> numeric value in the rounded to 2 decimal<o:p></o:p></pre><pre> places. If not, returns original value.<o:p></o:p></pre><pre>*************************************************/<o:p></o:p></pre><pre> var objRegExp = /-?[0-9]+\.[0-9]{2}$/;<o:p></o:p></pre><pre><o:p> </o:p></pre><pre> if( objRegExp.test(strValue)) {<o:p></o:p></pre><pre> objRegExp.compile('^-');<o:p></o:p></pre><pre> strValue = addCommas(strValue);<o:p></o:p></pre><pre> if (objRegExp.test(strValue)){<o:p></o:p></pre><pre> strValue = '(' + strValue.replace(objRegExp,'') + ')';<o:p></o:p></pre><pre> }<o:p></o:p></pre><pre> return '$' + strValue;<o:p></o:p></pre><pre> }<o:p></o:p></pre><pre> else<o:p></o:p></pre><pre> return strValue;<o:p></o:p></pre><pre>}<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>function removeCommas( strValue ) {<o:p></o:p></pre><pre>/************************************************<o:p></o:p></pre><pre>DESCRIPTION: Removes commas from source string.<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>PARAMETERS:<o:p></o:p></pre><pre> strValue - Source string from which commas will<o:p></o:p></pre><pre> be removed;<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>RETURNS: Source string with commas removed.<o:p></o:p></pre><pre>*************************************************/<o:p></o:p></pre><pre> var objRegExp = /,/g; //search for commas globally<o:p></o:p></pre><pre><o:p> </o:p></pre><pre> //replace all matches with empty strings<o:p></o:p></pre><pre> return strValue.replace(objRegExp,'');<o:p></o:p></pre><pre>}<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>function addCommas( strValue ) {<o:p></o:p></pre><pre>/************************************************<o:p></o:p></pre><pre>DESCRIPTION: Inserts commas into numeric string.<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>PARAMETERS:<o:p></o:p></pre><pre> strValue - source string containing commas.<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>RETURNS: String modified with comma grouping if<o:p></o:p></pre><pre> source was all numeric, otherwise source is<o:p></o:p></pre><pre> returned.<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>REMARKS: Used with integers or numbers with<o:p></o:p></pre><pre> 2 or less decimal places.<o:p></o:p></pre><pre>*************************************************/<o:p></o:p></pre><pre> var objRegExp = new RegExp('(-?[0-9]+)([0-9]{3})');<o:p></o:p></pre><pre><o:p> </o:p></pre><pre> //check for match to search criteria<o:p></o:p></pre><pre> while(objRegExp.test(strValue)) {<o:p></o:p></pre><pre> //replace original string with first group match,<o:p></o:p></pre><pre> //a comma, then second group match<o:p></o:p></pre><pre> strValue = strValue.replace(objRegExp, '$1,$2');<o:p></o:p></pre><pre> }<o:p></o:p></pre><pre> return strValue;<o:p></o:p></pre><pre>}<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>function removeCharacters( strValue, strMatchPattern ) {<o:p></o:p></pre><pre>/************************************************<o:p></o:p></pre><pre>DESCRIPTION: Removes characters from a source string<o:p></o:p></pre><pre> based upon matches of the supplied pattern.<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>PARAMETERS:<o:p></o:p></pre><pre> strValue - source string containing number.<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>RETURNS: String modified with characters<o:p></o:p></pre><pre> matching search pattern removed<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>USAGE: strNoSpaces = removeCharacters( ' sfdf dfd',<o:p></o:p></pre><pre> '\s*')<o:p></o:p></pre><pre>*************************************************/<o:p></o:p></pre><pre> var objRegExp = new RegExp( strMatchPattern, 'gi' );<o:p></o:p></pre><pre><o:p> </o:p></pre><pre> //replace passed pattern matches with blanks<o:p></o:p></pre><pre> return strValue.replace(objRegExp,'');<o:p></o:p></pre><pre>}<o:p></o:p></pre> <p class=MsoNormal><span style='font-size:10.0pt'>You can try it <a href="http://rgagnon.com/examples/jsregexp.html">here</a>.</span> <o:p></o:p></p> <p>If you want to know more about these MSDN pages :<br> <a href="http://msdn.microsoft.com/scripting/jscript/doc/jsobjregexp.htm" target="_top">RegExp Object</a><br> <a href="http://msdn.microsoft.com/scripting/jscript/doc/jsgrpregexpsyntax.htm" target="_top">Regular Expression Syntax</a> <o:p></o:p></p> <h1>Common expressions<o:p></o:p></h1> <pre><b>Date</b><o:p></o:p></pre><pre> /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/ mm/dd/yyyy<o:p></o:p></pre><pre> <o:p></o:p></pre><pre><b>US zip code</b><o:p></o:p></pre><pre> /(^\d{5}$)|(^\d{5}-\d{4}$)/ 99999 or 99999-9999<o:p></o:p></pre><pre> <o:p></o:p></pre><pre><b>Canadian postal code</b><o:p></o:p></pre><pre> /^\D{1}\d{1}\D{1}\-?\d{1}\D{1}\d{1}$/ Z5Z-5Z5 orZ5Z5Z5<o:p></o:p></pre><pre> <o:p></o:p></pre><pre><b>Time</b><o:p></o:p></pre><pre> /^([1-9]|1[0-2]):[0-5]\d(:[0-5]\d(\.\d{1,3})?)?$/ HH:MM or HH:MM:SS or HH:MM:SS.mmm<o:p></o:p></pre><pre> <o:p></o:p></pre><pre><b>IP Address(no check for alid values (0-255))</b><o:p></o:p></pre><pre> /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/ 999.999.999.999<o:p></o:p></pre><pre> <o:p></o:p></pre><pre><b>Dollar Amount</b><o:p></o:p></pre><pre> /^((\$\d*)|(\$\d*\.\d{2})|(\d*)|(\d*\.\d{2}))$/ 100, 100.00, $100 or $100.00<o:p></o:p></pre><pre> <o:p></o:p></pre><pre><b>Social Security Number</b><o:p></o:p></pre><pre> /^\d{3}\-?\d{2}\-?\d{4}$/ 999-99-9999 or999999999<o:p></o:p></pre><pre> <o:p></o:p></pre><pre><b>Canadian Social Insurance Number</b><o:p></o:p></pre><pre> <span lang=ES-UY>/^\d{9}$/ 999999999<o:p></o:p></span></pre><pre><span lang=ES-UY><o:p> </o:p></span></pre> <p class=MsoNormal><a href="http://rgagnon.com/jsdetails/js-0063.html"><span lang=ES-UY>http://rgagnon.com/jsdetails/js-0063.html</span></a><span lang=ES-UY><o:p></o:p></span></p> <p class=MsoNormal><span lang=ES-UY><o:p> </o:p></span></p> </div> Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1556630026494207117.post-40298929988204358362010-08-17T05:23:00.000-07:002010-08-17T05:23:57.345-07:00How to Replace All Occurrences of a String using Javascript Replace Function<h2 style="font-size: 100%;">Replace All Occurrences of a String using Javascript</h2> <p> In the second method where we used regular expression, if we identify the regular expression as a global regular expression we can easily replace all occurrences of a string within an other string value in a given text using Javascript.<br /></p> <p> How we can enable global regular expression is as simple as adding the "<b>g</b>" identifier following the regular expression.<br />Using "g" following the regular expression pattern, builtin javascript replace method will replace all matches and all occurences of the given text variable with the new string.<br /></p> <div id="div_global_regular_expression" class="samplecode"> <code> var string_variable;<br />string_variable = "Replace text using javascript replace function within a javascript string variable";<br />string_variable = string_variable.replace(/javascript/g, "js");<br />alert(string_variable);<br /></code> </div> As you can see in the sample javascript codes the implementation or the usage of the replace javascript function is so simple.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1556630026494207117.post-75125073035349178612010-08-12T23:23:00.001-07:002010-08-12T23:23:46.526-07:00SQL Server Date Time Format<div class=Section1> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>In SQL Server used Cast or Convert function to Format DateTime value or column into a specific date format.Both function are used to convert datetime to varchar or string.</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><b><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>CAST function Syntax:</span></b><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'> CAST(expression as data_type)</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>Let's convert current date time to varchar</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>select cast(getdate() as varchar)</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><b><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>CONVERT function</span></b><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'> is used to change or convert the DateTime formats.By using convert function you can get only Date part or only Time part from the datetime.</span><span style='font-size:12.0pt; font-family:"Times New Roman","serif"'><o:p></o:p></span></p> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif";background:yellow'>CONVERT Function Syntax:</span><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'> CONVERT(data_type,expression,date Format style)</span><span style='font-size: 12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>Let's take Sql Server DateTtime styles example:</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p> <table class=MsoNormalTable border=1 cellspacing=1 cellpadding=0 width="100%" style='width:100.0%'> <tr> <td width=271 style='width:203.1pt;padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><b><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>Format</span></b><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><b><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>Query</span></b><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> </tr> <tr> <td width=271 style='width:203.1pt;padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>USA mm/dd/yy</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>select convert(varchar, getdate(), 1)</span><span style='font-size:12.0pt; font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> </tr> <tr> <td width=271 style='width:203.1pt;padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>ANSI yy.mm.dd</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>select convert(varchar, getdate(), 2) </span><span style='font-size:12.0pt; font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> </tr> <tr> <td width=271 style='width:203.1pt;padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>British/French dd/mm/yy</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>select convert(varchar, getdate(), 3) </span><span style='font-size:12.0pt; font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> </tr> <tr> <td width=271 style='width:203.1pt;padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>German dd.mm.yy</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>select convert(varchar, getdate(), 4) </span><span style='font-size:12.0pt; font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> </tr> <tr> <td width=271 style='width:203.1pt;padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>Italian dd-mm-yy</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>select convert(varchar, getdate(), 5) </span><span style='font-size:12.0pt; font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> </tr> <tr> <td width=271 style='width:203.1pt;padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>dd mon yy</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>select convert(varchar, getdate(), 6) </span><span style='font-size:12.0pt; font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> </tr> <tr> <td width=271 style='width:203.1pt;padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>Mon dd, yy</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>select convert(varchar, getdate(), 7) </span><span style='font-size:12.0pt; font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> </tr> <tr> <td width=271 style='width:203.1pt;padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>USA mm-dd-yy</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>select convert(varchar, getdate(), 10) </span><span style='font-size:12.0pt; font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> </tr> <tr> <td width=271 style='width:203.1pt;padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>JAPAN yy/mm/dd</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>select convert(varchar, getdate(), 11) </span><span style='font-size:12.0pt; font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> </tr> <tr> <td width=271 style='width:203.1pt;padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>ISO yymmdd</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>select convert(varchar, getdate(), 12)</span><span style='font-size:12.0pt; font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> </tr> <tr> <td width=271 style='width:203.1pt;padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>mon dd yyyy hh:miAM (or PM)</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>select convert(varchar, getdate(), 100)</span><span style='font-size:12.0pt; font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> </tr> <tr> <td width=271 style='width:203.1pt;padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>mm/dd/yyyy</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>select convert(varchar, getdate(), 101)</span><span style='font-size:12.0pt; font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> </tr> <tr> <td width=271 style='width:203.1pt;padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>yyyy.mm.dd</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>select convert(varchar, getdate(), 102)</span><span style='font-size:12.0pt; font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> </tr> <tr> <td width=271 style='width:203.1pt;padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>dd/mm/yyyy</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>select convert(varchar, getdate(), 103)</span><span style='font-size:12.0pt; font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> </tr> <tr> <td width=271 style='width:203.1pt;padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>dd.mm.yyyy</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>select convert(varchar, getdate(), 104)</span><span style='font-size:12.0pt; font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> </tr> <tr> <td width=271 style='width:203.1pt;padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>dd-mm-yyyy</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>select convert(varchar, getdate(), 105)</span><span style='font-size:12.0pt; font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> </tr> <tr> <td width=271 style='width:203.1pt;padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>dd mon yyyy</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>select convert(varchar, getdate(), 106)</span><span style='font-size:12.0pt; font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> </tr> <tr> <td width=271 style='width:203.1pt;padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>Mon dd, yyyy</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>select convert(varchar, getdate(), 107)</span><span style='font-size:12.0pt; font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> </tr> <tr> <td width=271 style='width:203.1pt;padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>hh:mm:ss</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>select convert(varchar, getdate(), 108)</span><span style='font-size:12.0pt; font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> </tr> <tr> <td width=271 style='width:203.1pt;padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>Default + milliseconds mon dd yyyy hh:mi:ss:mmmAM (or PM)</span><span style='font-size: 12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>select convert(varchar, getdate(), 109)</span><span style='font-size:12.0pt; font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> </tr> <tr> <td width=271 style='width:203.1pt;padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>mm-dd-yyyy</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>select convert(varchar, getdate(), 110)</span><span style='font-size:12.0pt; font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> </tr> <tr> <td width=271 style='width:203.1pt;padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>yyyy/mm/dd</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>select convert(varchar, getdate(), 111)</span><span style='font-size:12.0pt; font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> </tr> <tr> <td width=271 style='width:203.1pt;padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>yyyymmdd</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>select convert(varchar, getdate(), 112)</span><span style='font-size:12.0pt; font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> </tr> <tr> <td width=271 style='width:203.1pt;padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>Europe default + milliseconds dd mon yyyy hh:mm:ss:mmm(24h) </span><span style='font-size: 12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>select convert(varchar, getdate(), 113) or select convert(varchar, getdate(), 13)</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> </tr> <tr> <td width=271 style='width:203.1pt;padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=ES-UY style='font-size:10.0pt;font-family:"Arial","sans-serif"'>hh:mi:ss:mmm(24h)</span><span lang=ES-UY style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>select convert(varchar, getdate(), 114)</span><span style='font-size:12.0pt; font-family:"Times New Roman","serif"'><o:p></o:p></span></p> </td> </tr> </table> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal>Origin: <a href="http://www.technoreader.com/SQL-Server-Date-Time-Format.aspx">http://www.technoreader.com/SQL-Server-Date-Time-Format.aspx</a><o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> </div> Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1556630026494207117.post-70510730757132038452010-08-09T23:29:00.001-07:002010-08-09T23:29:37.206-07:00Setting a variable from dynamic sql<div class=Section1> <p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><br> -- setting a variable from dynamic sql <br> Author Nigel Rivett <o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'><o:p> </o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>declare @i int<o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>exec sp_executesql N'select @i = 999', N'@i int output', @i output<o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>select @i<o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'><o:p> </o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'><o:p> </o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>-- setting output parameter from dynamic stored procedure call<o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'><o:p> </o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>declare @OutputParameter varchar(100) ,<o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'> @error int ,<o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'> @SPName varchar(128) ,<o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'> @SPCall nvarchar(128) ,<o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'> @rc int<o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>select @SPCall = 'exec ' + @SPName + ' @OutputParameter output'<o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>exec @rc = sp_executesql @SPCall, N'@OutputParameter varchar(100) output', @OutputParameter output<o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>select @Error = @@error<o:p></o:p></span></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal>reference: <a href="http://www.nigelrivett.net/SQLTsql/sp_executeSQL.html">http://www.nigelrivett.net/SQLTsql/sp_executeSQL.html</a><o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> </div> Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1556630026494207117.post-25783488826201840452010-06-22T01:20:00.000-07:002010-06-22T01:25:02.081-07:00<div xmlns='http://www.w3.org/1999/xhtml'><h1 class='single_title'>What Does “width: 100%” Do in CSS?</h1> <p class='post_info'>By Louis Lazaris on June 18th, 2010<br /> Categories: <a rel='category tag' title='View all posts in Markup & Style' href='http://www.impressivewebs.com/articles/markup-style/'>Markup & Style</a>, <a rel='category tag' title='View all posts in Web Design Articles' href='http://www.impressivewebs.com/articles/'>Web Design Articles</a> | <span class='post_comments'><a href='http://www.impressivewebs.com/width-100-percent-css/#commentsdown'>23 Comments</a></span></p> <p><img class='article_image' title='What Does width: 100% Do in CSS?' alt='What Does width: 100% Do in CSS?' src='http://www.impressivewebs.com/images/width-100-css.jpg' width='184' height='184'/>It seems like this should be one of the easiest things to understand in CSS. If you want a block-level element to fill any remaining space inside of its parent, then it’s simple — just add <code>width: 100%</code> in your CSS declaration for that element, and your problem is solved.</p> <p>Not so fast. It’s not quite that easy. I’m sure CSS developers of all skill levels have attempted something similar to what I’ve just described, with bizarre results ultimately leading to head scratching and shruggingly resorting to experimenting with absolute widths until we find just the right fit. This is just one of those things in CSS that seems easy to understand (and really, it should be), but it’s sometimes not — because of the way that percentages work in CSS.</p> <h2>First Things First: Blocks Don’t Need 100% Width</h2> <p>When we understand the difference between block-level elements and inline elements, we’ll know that a block element (such as a <code><div></code>, <code><p></code>, or <code><ul></code>, to name a few) will, by default expand to fit the width of its containing, or parent, element (minus any margins it has or padding its parent has).</p> <p><img class='wide_image' title='A Block-Level Element Expands Naturally' alt='A Block-Level Element Expands Naturally' src='http://www.impressivewebs.com/images/block-element-noneed.jpg' width='550' height='300'/></p> <p>Most CSS developers understand this concept pretty well, but I thought it would be useful to point it out here as an introduction to explaining how percentages work when used on the width property.</p> <h2>What it Really Means</h2> <p>When you give an element a width of 100% in CSS, you’re basically saying “Make this element’s content area exactly equal to the explicit width of its parent — but only if its parent has an explicit width.” So, if you have a parent container that’s 400px wide, a child element given a width of 100% will also be 400px wide, and will still be subject to margins, paddings, and borders — <strong><em>on top of the 100% width setting</em></strong>. The image below attempts to illustrate this:</p> <p><img class='wide_image' title='The child's content area will equal the parent's' alt='The child's content area will equal the parent's' src='http://www.impressivewebs.com/images/child-equal.jpg' width='550' height='500'/></p> <p>And of course, the exact same rule would apply to any percentage value. The content area will be the percentage of the parent’s explicitly-set width setting.</p> <p>NOTE ADDED: The width of the child’s content area will equal the width of the parent’s content area, but will not move outside the parent unless its own padding or margins are affecting it. Thanks to the <a href='http://www.impressivewebs.com/width-100-percent-css/#comment-3626'>comment by Fabio Brendolin</a> for clarifying this.</p> <h2>Should it Ever Be Used?</h2> <p>In 99% of cases, applying <code>width: 100%</code> to a block level element is either unnecessary or will bring undesirable results. The only time that I can think of when you need to give an element a width of 100% is when the element is inheriting a set width value that you want to override. But even in this case, the correct option would be to use “width: auto”, which is the default for block elements.</p> <h2>Height Works the Same Way (in All Browsers!)</h2> <p>And this little lesson provides a reminder of one of the frustrating things about CSS layouts — that you can’t give an element a height that fills its parent, unless the parent is given (you guessed it) an explicit height setting. The only difference is that in this case “auto” will not work, but instead “height: 100%” is required.</p> <p>And the great part is that all browsers (even IE6 and IE7) use percentage height exactly the same (IE bugs excluded), so as long as you explicitly set a width on the parent, the child element will fill the height to 100% as expected.</p> <h2>On a Side Note: “Remainder” should be a value</h2> <p>As a side note to all of this, there are some cases where a group of floated child elements will have varying widths, and it would be great to be able to just tell the last element “fill the remaining space”. On my personal CSS wish list would be a property/value setting as follows:</p> <div class='dp-highlighter'><div class='bar'><div class='tools'><a onclick='dp.sh.Toolbar.Command('ViewSource',this);return false;' href='http://www.impressivewebs.com/width-100-percent-css/#'>view plain</a><a onclick='dp.sh.Toolbar.Command('CopyToClipboard',this);return false;' href='http://www.impressivewebs.com/width-100-percent-css/#'>copy to clipboard</a><a onclick='dp.sh.Toolbar.Command('PrintSource',this);return false;' href='http://www.impressivewebs.com/width-100-percent-css/#'>print</a><a onclick='dp.sh.Toolbar.Command('About',this);return false;' href='http://www.impressivewebs.com/width-100-percent-css/#'>?</a></div></div><ol start='1' class='dp-css'><li class='alt'><span><span class='colors'>#elemen</span><span>t { </span></span></li><li class=''><span> <span class='keyword'>width</span><span>: remainder; </span><span class='comment'>/* not valid, but I wish it was! */</span><span> </span></span></li><li class='alt'><span>} </span></li></ol></div><pre class='css' name='code' style='display: none;'>#element { width: remainder; /* not valid, but I wish it was! */ } </pre> <p>This would be nice, and would certainly make things easier in some circumstances.</p> <p>What do you think? Have you ever misinterpreted percentage widths, and abandoned using them because they didn’t work as you expected? I know I’ve done this, and it took me quite some time to get it right and understand them better.</p><blockquote/></div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1556630026494207117.post-16985035987506988782010-06-17T07:23:00.000-07:002010-06-17T07:27:24.350-07:00web application development best practices<div class=Section1> <h1>Top 10 Best Practices for Production ASP.NET Applications<o:p></o:p></h1> <p class=MsoNormal><span class=post-day><i>12 Feb</i></span><em><span style='font-family:"Calibri","sans-serif"'>, 2008.</span></em> <o:p></o:p></p> <p>In no particular order, here are the top ten things I've learned to pay attention to when dealing with production ASP.NET applications. Hopefully they will help you save you some time and headaches. As always, your thoughts and additions are welcome.<o:p></o:p></p> <h2>1. Generate new encryption keys<o:p></o:p></h2> <p>When moving an application to production for the first time it is a good idea to generate new encryption keys. This includes the machine validation key and decryption key as well as any other custom keys your application may be using. There is <a href="http://www.codeproject.com/KB/aspnet/machineKey.aspx" target="_blank" title="ASP.NET machineKey Generator">an article on CodeProject</a> that talks about generating machineKeys specifically that should be helpful with this.<o:p></o:p></p> <h2>2. Encrypt sensitive sections of your web.config<o:p></o:p></h2> <p>This includes both the connection string and machine key sections. See <a href="http://weblogs.asp.net/scottgu/archive/2006/01/09/434893.aspx" target="_blank" title="Encrypting Web.Config Values in ASP.NET 2.0">Scott Guthrie's post</a> for some good references. Note that if your application runs in a clustered environment you will need to share a custom key using the RSA provider as described in an <a href="http://msdn2.microsoft.com/en-us/library/68ze1hb2%28VS.80%29.aspx" target="_blank" title="Specifying a Protected Configuration Provider">MSDN article</a>.<o:p></o:p></p> <h2>3. Use trusted SQL connections<o:p></o:p></h2> <p>Both <a href="http://idunno.org/articles/276.aspx" target="_blank" title="Using SQL trusted Connections with ASP.NET">Barry Dorrans</a> and <a href="http://weblogs.asp.net/achang/archive/2004/04/15/113866.aspx" target="_blank" title="How to use Trusted Connection when SQL server and web Server are on two separate machines">Alex Chang</a> have articles which discuss this in detail.<o:p></o:p></p> <h2>4. Set retail="true" in your machine.config<o:p></o:p></h2> <p class=MsoNormal style='margin-left:.5in'><configuration><br> <system.web><br> <deployment retail="true"/><br> </system.web><br> </configuration><br> <br> This will kill three birds with one stone. It will force the 'debug' flag in the web.config to be false, it will disable page output tracing, and it will force the custom error page to be shown to remote users rather than the actual exception or error message. For more information you can read <a href="http://weblogs.asp.net/scottgu/archive/2006/04/11/442448.aspx" target="_blank" title="Don't run production ASP.NET Applications with debug="true" enabled, by Scott Guthrie">Scott Guthrie's post</a> or the <a href="http://msdn2.microsoft.com/en-us/library/ms228298%28VS.80%29.aspx" target="_blank" title="maching.config deployment element (ASP.NET Settings Schema)">MSDN reference</a>.<o:p></o:p></p> <h2>5. Create a new application pool for your site<o:p></o:p></h2> <p>When setting up your new site for the first time do not share an existing application pool. Create a new application pool which will be used by only by the new web application.<o:p></o:p></p> <h2>6. Set the memory limit for your application pool<o:p></o:p></h2> <p>When creating the application pool, specifically set the memory limit rather than the time limit which is set by default. <a href="http://www.asp.net" target="_blank">Asp.net</a> has a <a href="http://www.asp.net/learn/whitepapers/aspnet-and-iis6/" target="_blank" title="Running ASP.NET 1.1 with IIS 6.0">good whitepaper</a> which explains the value of this:<o:p></o:p></p> <p>By default IIS 6.0 does not set a limit on the amount of memory that IIS is allowed to use. ASP.NET’s Cache feature relies on a limitation of memory so the Cache can proactively remove unused items from memory. <o:p></o:p></p> <p>It is recommended that you configure the memory recycling feature of IIS 6.0.<o:p></o:p></p> <h2>7. Create and appropriately use an app_Offline.htm file<o:p></o:p></h2> <p>There are many benefits to using this file. It provides an easy way to take your application offline in a somewhat user friendly way (you can at least have a pretty explanation) while fixing critical issues or pushing a major update. It also forces an application restart in case you forget to do this for a deployment. Once again, ScottGu is the <a href="http://weblogs.asp.net/scottgu/archive/2006/04/09/442332.aspx" target="_blank" title="App_Offline.htm and working around the "IE Friendly Errors" feature">best source</a> for more information on this.<o:p></o:p></p> <h2>8. Develop a repeatable deployment process and automate it<o:p></o:p></h2> <p>It is way too easy to make mistakes when deploying any type of software. This is especially the case with software that uses configuration files that may be different between the development, staging, or production environments. I would argue that the process you come up with is not nearly as important as it being easily repeatable and automated. You can fine tune the process as needed, but you don't want a simple typo to bring a site down.<o:p></o:p></p> <h2>9. Build and reference release versions of all assemblies<o:p></o:p></h2> <p>In addition to making sure ASP.NET is not configured in debug mode, also make sure that your assemblies are not debug assemblies. There are of course exceptions if you are trying to solve a unique issue in your production environment ... but in most cases you should always deploy with release builds for all assemblies.<o:p></o:p></p> <h2>10. Load test<o:p></o:p></h2> <p>This goes without saying. Inevitably, good load testing will uncover threading and memory issues not otherwise considered.<o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal><b>Introduction</b> <br> Performance tuning can be tricky. It's especially tough in Internet-related projects with lots of components running around, like HTML client, HTTP network, Web server, middle-tier components, database components, resource-management components, TCP/IP networks, and database servers. Performance tuning depends on a lot of parameters and sometimes, by changing a single parameter, performance can increase drastically.<o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal>This document lists out some tips for optimizing ASP.Net Web applications and many traps and pitfalls are discussed as follows : <br> <br> <br> <span class=articleparagraphtitle>Tips For Web Application</span><br> <br> <br> <b>1) Turn off Tracing unless until required</b> <br> Tracing is one of the wonderful features which enable us to track the application's trace and the sequences. However, again it is useful only for developers and you can set this to "false" unless you require to monitor the trace logging. <br> <u>How it affects performance:</u> <br> Enabling tracing adds performance overhead and might expose private information, so it should be enabled only while an application is being actively analyzed. <br> <u>Solution:</u> <br> When not needed, tracing can be turned off using <br> <i><trace enabled="false" requestLimit=”10” pageoutput=”false” traceMode=”SortByTime” localOnly=”true”></i> <br> <br> <br> <b>2) Turn off Session State, if not required</b> <br> One extremely powerful feature of ASP.NET is its ability to store session state for users, such as a shopping cart on an e-commerce site or a browser history. <br> <u>How it affects performance:</u> <br> Since ASP.NET Manages session state by default, you pay the cost in memory even if you don't use it. I.e. whether you store your data in in-process or on state server or in a Sql Database, session state requires memory and it's also time consuming when you store or retrieve data from it. <br> <u>Solution:</u> <br> You may not require session state when your pages are static or when you do not need to store information captured in the page. <br> In such cases where you need not use session state, disable it on your web form using the directive, <br> <i><@%Page EnableSessionState="false"%></i> <br> In case you use the session state only to retrieve data from it and not to update it, make the session state read only by using the directive, <br> <i><@%Page EnableSessionState ="ReadOnly"%> </i><br> <br> <b>3) Disable View State of a Page if possible</b> <br> View state is a fancy name for ASP.NET storing some state data in a hidden input field inside the generated page. When the page is posted back to the server, the server can parse, validate, and apply this view state data back to the page's tree of controls. <br> View state is a very powerful capability since it allows state to be persisted with the client and it requires no cookies or server memory to save this state. Many ASP.NET server controls use view state to persist settings made during interactions with elements on the page, for example, saving the current page that is being displayed when paging through data. <br> <u>How it affects performance:</u> <br> ? There are a number of drawbacks to the use of view state, however. <br> ? It increases the total payload of the page both when served and when requested. There is also an additional overhead incurred when serializing or deserializing view state data that is posted back to the server. <br> ? View state increases the memory allocations on the server. Several server controls, the most well known of which is the DataGrid, tend to make excessive use of view state, even in cases where it is not needed. <br> <u>Solution:</u> <br> Pages that do not have any server postback events can have the view state turned off. <br> The default behavior of the ViewState property is enabled, but if you don't need it, you can turn it off at the control or page level. Within a control, simply set the EnableViewState property to false, or set it globally within the page using this setting: <br> <i><%@ Page EnableViewState="false" %></i> <br> If you turn view state off for a page or control, make sure you thoroughly test your pages to verify that they continue to function correctly. <br> <br> <br> <b>4) Set debug=false in web.config</b> <br> When you create the application, by default this attribute is set to "true" which is very useful while developing. However, when you are deploying your application, always set it to "false". <br> <u>How it affects performance:</u> <br> Setting it to "true" requires the pdb information to be inserted into the file and this results in a comparatively larger file and hence processing will be slow. <br> <u>Solution:</u> <br> Therefore, always set <i>debug="false"</i> before deployment. <br> <br> <b>5) Avoid Response.Redirect</b> <br> Response.Redirect () method simply tells the browser to visit another page. <br> <u>How it affects performance:</u> <br> Redirects are also very chatty. They should only be used when you are transferring people to another physical web server. <br> <u>Solution:</u> <br> For any transfers within your server, use .transfer! You will save a lot of needless HTTP requests. Instead of telling the browser to redirect, it simply changes the "focus" on the Web server and transfers the request. This means you don't get quite as many HTTP requests coming through, which therefore eases the pressure on your Web server and makes your applications run faster. <br> <br> <u>Tradeoffs:</u> <br> ? ".transfer" process can work on only those sites running on the server. Only <u>Response.Redirect </u>can do that. <br> ? Server.Transfer maintains the original URL in the browser. This can really help streamline data entry techniques, although it may make for confusion when debugging <br> 5. A) To reduce CLR Exceptions count, Use Response.Redirect (".aspx", false) instead of <u>response.redirect (".aspx").</u> <br> <br> <b>6) Use the String builder to concatenate string</b> <br> <u>How it affects performance:</u> <br> String is Evil when you want to append and concatenate text to your string. All the activities you do to the string are stored in the memory as separate references and it must be avoided as much as possible. <br> i.e. When a string is modified, the run time will create a new string and return it, leaving the original to be garbage collected. Most of the time this is a fast and simple way to do it, but when a string is being modified repeatedly it begins to be a burden on performance: all of those allocations eventually get expensive. <br> <u>Solution:</u> <br> Use String Builder when ever string concatenation is needed so that it only stores the value in the original string and no additional reference is created. <br> <br> <br> <b>7) Avoid throwing exceptions</b> <br> <u>How it affects performance:</u> <br> Exceptions are probably one of the heaviest resource hogs and causes of slowdowns you will ever see in web applications, as well as windows applications. <br> <u>Solution:</u> <br> You can use as many try/catch blocks as you want. Using exceptions gratuitously is where you lose performance. For example, you should stay away from things like using exceptions for control flow. <br> <br> <b>8) Use Finally Method to kill resources</b> <br> ?The finally method gets executed independent of the outcome of the Block. <br> ?Always use the finally block to kill resources like closing database connection, closing files and other resources such that they get executed independent of whether the code worked in Try or went to Catch. <br> <br> <b>9) Use Client Side Scripts for validations</b> <br> User Input is Evil and it must be thoroughly validated before processing to avoid overhead and possible injections to your applications. <br> <u>How It improves performance: </u><br> Client site validation can help reduce round trips that are required to process user's request. In ASP.NET you can also use client side controls to validate user input. However, do a check at the Server side too to avoid the infamous Javascript disabled scenarios. <br> <br> <b>10) Avoid unnecessary round trips to the server</b> <br> <u>How it affects performance:</u> <br> Round trips significantly affect performance. They are subject to network latency and to downstream server latency. Many data-driven Web sites heavily access the database for every user request. While connection pooling helps, the increased network traffic and processing load on the database server can adversely affect performance. <br> <u>Solution:</u> <br> ? Keep round trips to an absolute minimum <br> ? Implement Ajax UI whenever possible. The idea is to avoid full page refresh and only update the portion of the page that needs to be changed <br> <br> <b>11) Use Page.ISPostBack</b> <br> Make sure you don't execute code needlessly. Use Page.ISPostBack property to ensure that you only perform page initialization logic when a page is first time loaded and not in response to client postbacks. <br> <br> <b>12) Include Return Statements with in the Function/Method </b><br> <u>How it improves performance</u> <br> Explicitly using return allows the JIT to perform slightly more optimizations. Without a return statement, each function/method is given several local variables on stack to transparently support returning values without the keyword. Keeping these around makes it harder for the JIT to optimize, and can impact the performance of your code. Look through your functions/methods and insert return as needed. It doesn't change the semantics of the code at all, and it can help you get more speed from your application. <br> <br> <b>13) Use Foreach loop instead of For loop for String Iteration </b><br> Foreach is far more readable, and in the future it will become as fast as a For loop for special cases like strings. Unless string manipulation is a real performance hog for you, the slightly messier code may not be worth it. <br> <br> <b>14) Avoid Unnecessary Indirection</b> <br> <u>How it affects performance:</u> <br> When you use byRef, you pass pointers instead of the actual object. <br> Many times this makes sense (side-effecting functions, for example), but you don't always need it. Passing pointers results in more indirection, which is slower than accessing a value that is on the stack. <br> <u>Solution:</u> <br> When you don't need to go through the heap, it is best to avoid it there by avoiding indirection. <br> <br> <b>15) Use "ArrayLists" in place of arrays</b> <br> <u>How it improves performance</u> <br> An ArrayList as everything that is good about an array PLUS automatic sizing, Add, Insert, Remove, Sort, Binary Search. All these great helper methods are added when implementing the IList interface. <br> <u>Tradeoffs:</u> <br> The downside of an ArrayList is the need to cast objects upon retrieval. <br> <br> <b>16) Always check Page.IsValid when using Validator Controls</b> <br> Always make sure you check Page.IsValid before processing your forms when using Validator Controls. <br> <br> <b>17) Use Paging</b> <br> Take advantage of paging's simplicity in .net. Only show small subsets of data at a time, allowing the page to load faster. <br> <u>Tradeoffs:</u> <br> Just be careful when you mix in caching. Don't cache all the data in the grid. <br> <br> <b>18) Store your content by using caching</b> <br> <u>How it improves performance:</u> <br> ASP.NET allows you to cache entire pages, fragment of pages or controls. You can cache also variable data by specifying the parameters that the data depends. By using caching you help ASP.NET engine to return data for repeated request for the same page much faster. <br> When and Why Use Caching: <br> A Proper use and fine tune of caching approach of caching will result on better performance and scalability of your site. However improper use of caching will actually slow down and consume lots of your server performance and memory usage. <br> Good candidate to use caching is if you have infrequent chance of data or static content of web page. <br> <br> <b>19) Use low cost authentication</b> <br> Authentication can also have an impact over the performance of your application. For example passport authentication is slower than form-base authentication which in here turn is slower than Windows authentication. <br> <br> <b>20) Minimize the number of web server controls</b> <br> <u>How it affects performance:</u> <br> The use of web server controls increases the response time of your application because they need time to be processed on the server side before they are rendered on the client side. <br> <u>Solution:</u> <br> One way to minimize the number of web server controls is to taking into consideration, the usage of HTML elements where they are suited, for example if you want to display static text. <br> <br> <b>21) Avoid using unmanaged code</b> <br> <u>How it affects performance:</u> <br> Calls to unmanaged code are a costly marshaling operation. <br> <u>Solution:</u> <br> Try to reduce the number calls between the managed and unmanaged code. Consider to do more work in each call rather than making frequent calls to do small tasks. <br> <br> <b>22) Avoid making frequent calls across processes</b> <br> If you are working with distributed applications, this involves additional overhead negotiating network and application level protocols. In this case network speed can also be a bottleneck. Try to do as much work as possible in fewer calls over the network. <br> <br> <b>23) Cleaning Up Style Sheets and Script Files</b> <br> ? A quick and easy way to improve your web application's performance is by going back and cleaning up your CSS Style Sheets and Script Files of unnecessary code or old styles and functions. It is common for old styles and functions to still exist in your style sheets and script files during development cycles and when improvements are made to a website. <br> ? Many websites use a single CSS Style Sheet or Script File for the entire website. Sometimes, just going through these files and cleaning them up can improve the performance of your site by reducing the page size. If you are referencing images in your style sheet that are no longer used on your website, it's a waste of performance to leave them in there and have them loaded each time the style sheet is loaded. <br> ? Run a web page analyzer against pages in your website so that you can see exactly what is being loaded and what takes the most time to load. <br> <br> <b>24) Design with ValueTypes </b><br> Use simple structs when you can, and when you don't do a lot of boxing <br> and unboxing. <br> <u>Tradeoffs:</u> <br> ValueTypes are far less flexible than Objects, and end up hurting performance if used incorrectly. You need to be very careful about when you treat them like objects. This adds extra boxing and unboxing overhead to your program, and can end up costing you more than it would if you had stuck with objects. <br> <br> <b>25) Minimize assemblies</b> <br> Minimize the number of assemblies you use to keep your working set small. If you load an entire assembly just to use one method, you're paying a tremendous cost for very little benefit. See if you can duplicate that method's functionality using code that you already have loaded. <br> <br> <b>26) Encode Using ASCII When You Don't Need UTF </b><br> By default, ASP.NET comes configured to encode requests and responses as UTF-8. <br> If ASCII is all your application needs, eliminated the UTF overhead can give you back a few cycles. Note that this can only be done on a per-application basis. <br> <br> <b>27) Avoid Recursive Functions / Nested Loops</b> <br> These are general things to adopt in any programming language, which consume lot of memory. Always avoid Nested Loops, Recursive functions, to improve performance. <br> <br> <b>28) Minimize the Use of Format () </b><br> When you can, use toString () instead of format (). In most cases, it will provide you with the functionality you need, with much less overhead. <br> <br> <b>29) Place StyleSheets into the Header</b> <br> Web developers who care about performance want browser to load whatever content it has as soon as possible. This fact is especially important for pages with a lot of content and for users with slow Internet connections. When the browser loads the page progressively the header, the logo, the navigation components serve as visual feedback for the user. <br> When we place style sheets near the bottom part of the html, most browsers stop rendering to avoid redrawing elements of the page if their styles change thus decreasing the performance of the page. So, always place StyleSheets into the Header <br> <br> <b>30) Put Scripts to the end of Document</b> <br> Unlike StyleSheets, it is better to place scripts to the end of the document. Progressive rendering is blocked until all StyleSheets have been downloaded. Scripts cause progressive rendering to stop for all content below the script until it is fully loaded. Moreover, while downloading a script, browser does not start any other component downloads, even on different hostnames. <br> So,always have scripts at the end of the document. <br> <br> <b>31) Make JavaScript and CSS External</b> <br> Using external files generally produces faster pages because the JavaScript and CSS files are cached by the browser. Inline JavaScript and CSS increases the HTML document size but reduces the number of HTTP requests. With cached external files, the size of the HTML is kept small without increasing the number of HTTP requests thus improving the performance. <br> <br> <br> <span class=articleparagraphtitle>Tips For Database Operations</span><br> <br> <br> <b>1) Return Multiple Resultsets</b> <br> The database code if has request paths that go to the database more than once then, these round-trips decreases the number of requests per second your application can serve. <br> <u>Solution:</u> <br> Return multiple resultsets in a single database request, so that you can cut the total time spent communicating with the database. You'll be making your system more scalable, too, as you'll cut down on the work the database server is doing managing requests. <br> <br> <b>2) Connection Pooling and Object Pooling</b> <br> Connection pooling is a useful way to reuse connections for multiple requests, rather than paying the overhead of opening and closing a connection for each request. It's done implicitly, but you get one pool per unique connection string. Make sure you call Close or Dispose on a connection as soon as possible. When pooling is enabled, calling Close or Dispose returns the connection to the pool instead of closing the underlying database connection. <br> Account for the following issues when pooling is a part of your design: <br> ? Share connections <br> ? Avoid per-user logons to the database <br> ? Do not vary connection strings <br> ? Do not cache connections <br> <br> <b>3) Use SqlDataReader Instead of Dataset wherever it is possible</b> <br> If you are reading a table sequentially you should use the DataReader rather than DataSet. DataReader object creates a read only stream of data that will increase your application performance because only one row is in memory at a time. <br> <br> <b>4) Keep Your Datasets Lean</b> <br> Remember that the dataset stores all of its data in memory, and that the more data you request, the longer it will take to transmit across the wire. <br> Therefore Only put the records you need into the dataset. <br> <br> <b>5) Avoid Inefficient queries</b> <br> <u>How it affects performance:</u> <br> Queries that process and then return more columns or rows than necessary, waste processing cycles that could best be used for servicing other requests. <br> <br> <u>Cause of Inefficient queries:</u> <br> ? Too much data in your results is usually the result of inefficient queries. <br> ? The SELECT * query often causes this problem. You do not usually need to return all the columns in a row. Also, analyze the WHERE clause in your queries to ensure that you are not returning too many rows. Try to make the WHERE clause as specific as possible to ensure that the least number of rows are returned. <br> ? Queries that do not take advantage of indexes may also cause poor performance. <br> <br> <b>6) Unnecessary round trips</b> <br> <u>How it affects performance:</u> <br> Round trips significantly affect performance. They are subject to network latency and to downstream server latency. Many data-driven Web sites heavily access the database for every user request. While connection pooling helps, the increased network traffic and processing load on the database server can adversely affect performance. <br> <u>Solution:</u> <br> Keep round trips to an absolute minimum. <br> <br> <b>7) Too many open connections</b> <br> Connections are an expensive and scarce resource, which should be shared between callers by using connection pooling. Opening a connection for each caller limits scalability. <br> <u>Solution:</u> <br> To ensure the efficient use of connection pooling, avoid keeping connections open and avoid varying connection strings. <br> <br> <b>8) Avoid Transaction misuse</b> <br> <u>How it affects performance:</u> <br> If you select the wrong type of transaction management, you may add latency to each operation. Additionally, if you keep transactions active for long periods of time, the active transactions may cause resource pressure. <br> <u>Solution:</u> <br> Transactions are necessary to ensure the integrity of your data, but you need to ensure that you use the appropriate type of transaction for the shortest duration possible and only where necessary. <br> <br> <b>9) Avoid Over Normalized tables</b> <br> Over Normalized tables may require excessive joins for simple operations. These additional steps may significantly affect the performance and scalability of your application, especially as the number of users and requests increases. <br> <br> <b>10) Reduce Serialization</b> <br> Dataset serialization is more efficiently implemented in .NET Framework version 1.1 than in version 1.0. However, Dataset serialization often introduces performance bottlenecks. <br> You can reduce the performance impact in a number of ways: <br> ? Use column name aliasing <br> ? Avoid serializing multiple versions of the same data <br> ? Reduce the number of DataTable objects that are serialized <br> <br> <b>11) Do Not Use CommandBuilder at Run Time</b> <br> <u>How it affects performance:</u> <br> CommandBuilder objects such as as SqlCommandBuilder and OleDbCommandBuilder are useful when you are designing and prototyping your application. However, you should not use them in production applications. The processing required to generate the commands affects performance. <br> <u>Solution:</u> <br> Manually create stored procedures for your commands, or use the Visual Studio® .NET design-time wizard and customize them later if necessary. <br> <br> <b>12) Use Stored Procedures Whenever Possible</b> <br> ?Stored procedures are highly optimized tools that result in excellent performance when used effectively. <br> ?Set up stored procedures to handle inserts, updates, and deletes with the data adapter <br> ?Stored procedures do not have to be interpreted, compiled or even transmitted from the client, and cut down on both network traffic and server overhead. <br> ?Be sure to use CommandType.StoredProcedure instead of CommandType.Text <br> <br> <b>13) Avoid Auto-Generated Commands</b> <br> When using a data adapter, avoid auto-generated commands. These require additional trips to the server to retrieve meta data, and give you a lower level of interaction control. While using auto-generated commands is convenient, it's worth the effort to do it yourself in performance-critical applications. <br> <br> <b>14) Use Sequential Access as Often as Possible</b> <br> With a data reader, use CommandBehavior.SequentialAccess. This is essential for dealing with blob data types since it allows data to be read off of the wire in small chunks. While you can only work with one piece of the data at a time, the latency for loading a large data type disappears. If you don't need to work the whole object at once, using <br> Sequential Access will give you much better performance. <br> <br> <br> <span class=articleparagraphtitle>Tips for Asp.Net applications developed using VB</span><br> <br> <br> <b>1) Enable Option Strict and Option Explicit for your pages</b> <br> With Option Strict on, you protect yourself from inadvertent late binding and enforce a higher level of coding discipline. <br> <br> <b>2) Use early binding in Visual Basic or JScript code</b> <br> Visual Basic 6 does a lot of work under the hood to support casting of objects, and many programmers aren't even aware of it. In Visual Basic 7, this is an area that out of which you can squeeze a lot of performance. <br> <u>Solution:</u> <br> When you compile, use early binding. This tells the compiler to insert a Type Coercion is only done when explicitly mentioned. <br> This has two major effects: <br> ? Strange errors become easier to track down. <br> ? Unneeded coercions are eliminated, leading to substantial performance improvements. <br> When you use an object as if it were of a different type, Visual Basic will coerce the object for you if you don't specify. This is handy, since the programmer has to worry about less code. <br> <br> <b>3) Put Concatenations in One Expression</b> <br> If you have multiple concatenations on multiple lines, try to stick them all on one expression. The compiler can optimize by modifying the string in place, providing a speed and memory boost. If the statements are split into multiple lines, the Visual Basic compiler will not generate the Microsoft Intermediate Language (MSIL) to allow in-place concatenation. <br> <br> <b>Summary </b><br> When we talk about ASP.Net performance, there are lots of factors in place. <br> Above discussed are the most critical of the speed improvements you can make in ASP.net that will have a dramatic impact on the user experience of your web application. If you like this article, subscribe to our <a href="http://feeds2.feedburner.com/DotNetFundaArticles" title="Subscribe to RSS Feed"><span style='color:windowtext; text-decoration:none'><span style='color:blue'><img border=0 width=16 height=16 id="Picture_x0020_2" src="cid:image001.png@01CAF5B0.BD9888E0" alt="http://www.feedburner.com/fb/images/pub/feed-icon16x16.png"></span></span>RSS Feed</a>. You can also <a href="http://www.dotnetfunda.com/subscribe.aspx" title="Subscribe via email">subscribe via email</a> to our Interview Questions, Codes and Forums section. <o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal><o:p> </o:p></p> <h2>Introduction<o:p></o:p></h2> <p>ASP.NET is much more powerful than classic ASP, however it is important to understand how to use that power to build highly efficient, reliable and robust applications. In this article, I tried to highlight the key tips you can use to maximize the performance of your ASP.NET pages. The list can be much longer, I am only emphasizing the most important ones. <o:p></o:p></p> <h2>1. Plan and research before you develop<o:p></o:p></h2> <p>Research and investigate how .NET can really benefit you. .NET offers a variety of solutions on each level of application design and development. It is imperative that you understand your situation and pros and cons of each approach supported by this rich development environment. Visual Studio is a comprehensive development package and offers many options to implement the same logic. It is really important that you examine each option and find the best optimal solution suited for the task at hand. Use layering to logically partition your application logic into presentation, business, and data access layers. It will not only help you create maintainable code, but also permits you to monitor and optimize the performance of each layer separately. A clear logical separation also offers more choices for scaling your application. Try to reduce the amount of code in your code-behind files to improve maintenance and scalability.<o:p></o:p></p> <h2>2. String concatenation<o:p></o:p></h2> <p>If not handled properly, String Concatenation can really decrease the performance of your application. You can concatenate strings in two ways. <o:p></o:p></p> <ul type=disc> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l15 level1 lfo1'>First, by using string and adding the new string to an existing string. However, this operation is really expensive (especially if you are concatenating the string within a loop). When you add a string to an existing string, the Framework copies both the existing and new data to the memory, deletes the existing string, and reads data in a new string. This operation can be very time consuming and costly in lengthy string concatenation operations. <o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l15 level1 lfo1'>The second and better way to concatenate strings is using the <code><span style='font-size:10.0pt'>StringBuilder </span></code>Class. Below is an example of both approaches. If you are considering doing any type of String Concatenation, please do yourself a favor and test both routines separately. You may be surprised at the results. <o:p></o:p></li> </ul> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; margin-left:.5in'><img border=0 width=9 height=9 id=preimg0 src="cid:image002.gif@01CAF5B0.DF2B5A50" alt="http://www.codeproject.com/images/minus.gif">Collapse<o:p></o:p></p> <pre style='margin-left:.5in' id=pre0><span class=code-comment>'Concatenation using String Class <o:p></o:p></span></pre><pre style='margin-left:.5in'><o:p> </o:p></pre><pre style='margin-left:.5in'>Response.Write(<span class=code-string>"<b>String Class</b>"</span>)<o:p></o:p></pre><pre style='margin-left:.5in'><span class=code-keyword>Dim</span> str <span class=code-keyword>As</span> <span class=code-keyword>String</span> = <span class=code-string>""</span><o:p></o:p></pre><pre style='margin-left: .5in'><span class=code-keyword>Dim</span> startTime <span class=code-keyword>As</span> DateTime = DateTime.Now<o:p></o:p></pre><pre style='margin-left:.5in'>Response.Write((<span class=code-string>"<br>Start time:"</span> + startTime.ToString()))<o:p></o:p></pre><pre style='margin-left:.5in'><span class=code-keyword>Dim</span> i <span class=code-keyword>As</span> <span class=code-keyword>Integer</span><o:p></o:p></pre><pre style='margin-left:.5in'><span class=code-keyword>For</span> i = <span class=code-digit>0</span> <span class=code-keyword>To</span> <span class=code-digit>99999</span><o:p></o:p></pre><pre style='margin-left:.5in'>str += i.ToString()<o:p></o:p></pre><pre style='margin-left:.5in'><span class=code-keyword>Next</span> i<o:p></o:p></pre><pre style='margin-left:.5in'><span class=code-keyword>Dim</span> EndTime <span class=code-keyword>As</span> DateTime = DateTime.Now<o:p></o:p></pre><pre style='margin-left:.5in'>Response.Write((<span class=code-string>"<br>End time:"</span> + EndTime.ToString()))<o:p></o:p></pre><pre style='margin-left:.5in'>Response.Write((<span class=code-string>"<br># of time Concatenated: "</span> + i.ToString))<o:p></o:p></pre> <p style='margin-left:.5in'>Results: Took 4 minutes and 23 Seconds to to complete 100,000 Concatenations.<o:p></o:p></p> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; margin-left:.5in'><span class=code-sdkkeyword><span style='font-size:10.0pt; font-family:"Courier New"'>String</span></span> Class <o:p></o:p></p> <ul type=disc> <ul type=circle> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt: auto;mso-list:l15 level2 lfo1'>Start time: 2/15/2006 10:21:24 AM<o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt: auto;mso-list:l15 level2 lfo1'>End time: 2/15/2006 10:25:47 AM<o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt: auto;mso-list:l15 level2 lfo1'># of time Concatenated: 100000<o:p></o:p></li> </ul> </ul> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; margin-left:.5in'><img border=0 width=9 height=9 id=preimg1 src="cid:image002.gif@01CAF5B0.DF2B5A50" alt="http://www.codeproject.com/images/minus.gif">Collapse<o:p></o:p></p> <pre style='margin-left:.5in' id=pre1><span class=code-comment>'Concatenation using StringBuilder<o:p></o:p></span></pre><pre style='margin-left:.5in'><o:p> </o:p></pre><pre style='margin-left:.5in'> Response.Write(<span class=code-string>"<b>StringBuilder Class</b>"</span>)<o:p></o:p></pre><pre style='margin-left:.5in'> <span class=code-keyword>Dim</span> strbuilder <span class=code-keyword>As</span> <span class=code-keyword>New</span> StringBuilder()<o:p></o:p></pre><pre style='margin-left:.5in'> <span class=code-keyword>Dim</span> startTime <span class=code-keyword>As</span> DateTime = DateTime.Now<o:p></o:p></pre><pre style='margin-left:.5in'> Response.Write((<span class=code-string>"<br>Start time:"</span> + startTime.ToString()))<o:p></o:p></pre><pre style='margin-left:.5in'> <span class=code-keyword>Dim</span> i <span class=code-keyword>As</span> <span class=code-keyword>Integer</span><o:p></o:p></pre><pre style='margin-left:.5in'> <span class=code-keyword>For</span> i = <span class=code-digit>0</span> <span class=code-keyword>To</span> <span class=code-digit>99999</span><o:p></o:p></pre><pre style='margin-left:.5in'> strbuilder.Append(i.ToString())<o:p></o:p></pre><pre style='margin-left:.5in'> <span class=code-keyword>Next</span> i<o:p></o:p></pre><pre style='margin-left:.5in'> <span class=code-keyword>Dim</span> EndTime <span class=code-keyword>As</span> DateTime = DateTime.Now<o:p></o:p></pre><pre style='margin-left:.5in'> Response.Write((<span class=code-string>"<br>Stop time:"</span> + EndTime.ToString()))<o:p></o:p></pre><pre style='margin-left:.5in'> Response.Write((<span class=code-string>"<br># of time Concatenated: "</span> + i.ToString))<o:p></o:p></pre> <p style='margin-left:.5in'>Results: Took less than a Second to complete 100,000 Concatenations.<o:p></o:p></p> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; margin-left:.5in'><code><span style='font-size:10.0pt'>StringBuilder </span></code>Class <o:p></o:p></p> <ul type=disc> <ul type=circle> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt: auto;mso-list:l15 level2 lfo1'>Start time: 2/15/2006 10:31:22 AM<o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt: auto;mso-list:l15 level2 lfo1'>Stop time:2/15/2006 10:31:22 AM<o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt: auto;mso-list:l15 level2 lfo1'># of time Concatenated: 100000 <o:p></o:p></li> </ul> </ul> <p>This is one of the many situations in which ASP.NET provides extremely high performance benefits over classic ASP. <o:p></o:p></p> <h2>3. Avoid round trips to the server<o:p></o:p></h2> <p>You can avoid needless round trips to the Web Server using the following tips:<o:p></o:p></p> <ul type=disc> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l7 level1 lfo2'>Implement Ajax UI whenever possible. The idea is to avoid full page refresh and only update the portion of the page that needs to be changed. I think <a href="http://weblogs.asp.net/scottgu/archive/2006/01/01/434314.aspx">Scott's article</a> gave great information on how to implement Ajax Atlas and <span class=code-keyword><span style='font-size:10.0pt;font-family:"Courier New"'><</span></span><code><span style='font-size:10.0pt'>atlas:updatepanel</span></code><span class=code-keyword><span style='font-size:10.0pt;font-family:"Courier New"'>></span></span> control. <o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l7 level1 lfo2'>Use Client Side Scripts. Client site validation can help reduce round trips that are required to process user's request. In ASP.NET you can also use client side controls to validate user input. <o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l7 level1 lfo2'>Use <code><span style='font-size:10.0pt'>Page.ISPostBack </span></code>property to ensure that you only perform page initialization logic when a page is loaded the first time and not in response to client postbacks. <o:p></o:p></li> </ul> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; margin-left:.5in'><img border=0 width=9 height=9 id=preimg2 src="cid:image002.gif@01CAF5B0.DF2B5A50" alt="http://www.codeproject.com/images/minus.gif">Collapse<o:p></o:p></p> <pre style='margin-left:.5in' id=pre2><span class=code-keyword>If</span> <span class=code-keyword>Not</span> IsPostBack <span class=code-keyword>Then</span> <o:p></o:p></pre><pre style='margin-left:.5in'>LoadJScripts()<o:p></o:p></pre><pre style='margin-left: .5in'><span class=code-keyword>End</span> <span class=code-keyword>If</span><o:p></o:p></pre> <ul type=disc> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l7 level1 lfo2'>In some situations performing postback event handling are unnecessary. You can use client callbacks to read data from the server instead of performing a full round trip. <a href="http://msdn2.microsoft.com/en-us/library/ms178208.aspx">Click here for details.</a><o:p></o:p></li> </ul> <h2>4. Save viewstate only when necessary<o:p></o:p></h2> <p><code><span style='font-size:10.0pt'>ViewState </span></code>is used primarily by Server controls to retain state only on pages that post data back to themselves. The information is passed to the client and read back in a hidden variable. <code><span style='font-size:10.0pt'>ViewState </span></code>is an unnecessary overhead for pages that do not need it. As the <code><span style='font-size:10.0pt'>ViewState </span></code>grows larger, it affects the performance of garbage collection. You can optimize the way your application uses <code><span style='font-size:10.0pt'>ViewState </span></code>by following these tips: <o:p></o:p></p> <h3>Situation when you don't need ViewState<o:p></o:p></h3> <p><code><span style='font-size:10.0pt'>ViewState </span></code>is turned on in ASP.NET by default. You might not need <code><span style='font-size:10.0pt'>ViewState </span></code>because your page is output-only or because you explicitly reload data for each request. You do not need <code><span style='font-size:10.0pt'>ViewState </span></code>in the following situations: <o:p></o:p></p> <ul type=disc> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l0 level1 lfo3'>Your page does not post back. If the page does not post information back to itself, if the page is only used for output, and if the page does not rely on response processing, you do not need ViewState. <o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l0 level1 lfo3'>You do not handle server control events. If your server controls do not handle events, and if your server controls have no dynamic or data bound property values, or they are set in code on every request, you do not need <code><span style='font-size:10.0pt'>ViewState</span></code>. <o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l0 level1 lfo3'>You repopulate controls with every page refresh. If you ignore old data, and if you repopulate the server control each time the page is refreshed, you do not need <code><span style='font-size:10.0pt'>ViewState</span></code>. <o:p></o:p></li> </ul> <h3>Disabling viewstate<o:p></o:p></h3> <p>There are several ways to disable <code><span style='font-size:10.0pt'>ViewState </span></code>at various levels: <o:p></o:p></p> <ul type=disc> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l17 level1 lfo4'>To disable <code><span style='font-size:10.0pt'>ViewState </span></code>for a single control on a page, set the <code><span style='font-size:10.0pt'>EnableViewState </span></code>property of the control to <span class=code-keyword><span style='font-size:10.0pt; font-family:"Courier New"'>false</span></span>.<o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l17 level1 lfo4'>To disable <code><span style='font-size:10.0pt'>ViewState </span></code>for a single page, set the <code><span style='font-size: 10.0pt'>EnableViewState </span></code>attribute in the <code><span style='font-size:10.0pt'>@ Page </span></code>directive to <span class=code-keyword><span style='font-size:10.0pt;font-family:"Courier New"'>false</span></span>. i.e. <o:p></o:p></li> </ul> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; margin-left:.5in'><img border=0 width=9 height=9 id=preimg3 src="cid:image002.gif@01CAF5B0.DF2B5A50" alt="http://www.codeproject.com/images/minus.gif">Collapse<o:p></o:p></p> <pre style='margin-left:.5in' id=pre3><span class=code-pagedirective><%@</span><span class=code-leadattribute> Page EnableViewState</span><span class=code-keyword>="false"</span><span class=code-attribute> </span><span class=code-pagedirective>%></span> <o:p></o:p></pre> <ul type=disc> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l17 level1 lfo4'>To disable <code><span style='font-size:10.0pt'>ViewState </span></code>for a specific application, use the following element in the <em><span style='font-family:"Calibri","sans-serif"'>Web.config</span></em> file of the application: <o:p></o:p></li> </ul> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; margin-left:.5in'><img border=0 width=9 height=9 id=preimg4 src="cid:image002.gif@01CAF5B0.DF2B5A50" alt="http://www.codeproject.com/images/minus.gif">Collapse<o:p></o:p></p> <pre style='margin-left:.5in' id=pre4><span class=code-keyword><</span><span class=code-leadattribute>pages</span> <span class=code-attribute>enableViewState</span><span class=code-keyword>="false"</span> <span class=code-keyword>/></span><o:p></o:p></pre> <ul type=disc> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l17 level1 lfo4'>To disable <code><span style='font-size:10.0pt'>ViewState </span></code>for all applications on a Web server, configure the <span class=code-keyword><span style='font-size:10.0pt;font-family:"Courier New"'><</span></span><code><span style='font-size:10.0pt'>pages</span></code><span class=code-keyword><span style='font-size:10.0pt;font-family:"Courier New"'>></span></span> element in the <em><span style='font-family:"Calibri","sans-serif"'>Machine.config</span></em> file as follows: <o:p></o:p></li> </ul> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; margin-left:.5in'><img border=0 width=9 height=9 id=preimg5 src="cid:image002.gif@01CAF5B0.DF2B5A50" alt="http://www.codeproject.com/images/minus.gif">Collapse<o:p></o:p></p> <pre style='margin-left:.5in' id=pre5><span class=code-keyword><</span><span class=code-leadattribute>pages</span> <span class=code-attribute>enableViewState</span><span class=code-keyword>="false"</span> <span class=code-keyword>/></span><o:p></o:p></pre> <h3>Determine the size of your ViewState<o:p></o:p></h3> <p>By enabling tracing for the page, you can monitor the <code><span style='font-size:10.0pt'>ViewState </span></code>size for each control. You can use this information to determine the optimal size of the <code><span style='font-size:10.0pt'>ViewState </span></code>or if there are controls in which the <code><span style='font-size:10.0pt'>ViewState </span></code>can be disabled.<o:p></o:p></p> <h2>5. Use session variables carefully<o:p></o:p></h2> <p>Avoid storing too much data in session variables, and make sure your session timeout is reasonable. This can use a significant amount of server memory. Keep in mind that data stored in session variables can hang out long after the user closes the browser. Too many session variables can bring the server on its knees. Disable session state, if you are not using session variables in the particular page or application. <o:p></o:p></p> <ul type=disc> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l5 level1 lfo5'>To disable session state for a page, set the <code><span style='font-size:10.0pt'>EnableSessionState </span></code>attribute in the <code><span style='font-size:10.0pt'>@ Page </span></code>directive to <span class=code-keyword><span style='font-size:10.0pt;font-family:"Courier New"'>false</span></span>.i.e. <o:p></o:p></li> </ul> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; margin-left:.5in'><img border=0 width=9 height=9 id=preimg6 src="cid:image002.gif@01CAF5B0.DF2B5A50" alt="http://www.codeproject.com/images/minus.gif">Collapse<o:p></o:p></p> <pre style='margin-left:.5in' id=pre6><span class=code-pagedirective><%@</span><span class=code-leadattribute> Page EnableSessionState</span><span class=code-keyword>="false"</span><span class=code-attribute> </span><span class=code-pagedirective>%></span> <o:p></o:p></pre> <ul type=disc> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l5 level1 lfo5'>If a page requires access to session variables but will not create or modify them, set the <code><span style='font-size: 10.0pt'>EnableSessionState </span></code>attribute in the<code><span style='font-size:10.0pt'>@ Page </span></code>directive to <code><span style='font-size:10.0pt'>ReadOnly</span></code>. i.e. <o:p></o:p></li> </ul> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; margin-left:.5in'><img border=0 width=9 height=9 id=preimg7 src="cid:image002.gif@01CAF5B0.DF2B5A50" alt="http://www.codeproject.com/images/minus.gif">Collapse<o:p></o:p></p> <pre style='margin-left:.5in' id=pre7><span class=code-pagedirective><%@</span><span class=code-leadattribute> Page EnableSessionState</span><span class=code-keyword>="ReadOnly"</span><span class=code-attribute> </span><span class=code-pagedirective>%></span> <o:p></o:p></pre> <ul type=disc> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l5 level1 lfo5'>To disable session state for a specific application, use the following element in the <em><span style='font-family: "Calibri","sans-serif"'>Web.config</span></em> file of the application. <o:p></o:p></li> </ul> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; margin-left:.5in'><img border=0 width=9 height=9 id=preimg8 src="cid:image002.gif@01CAF5B0.DF2B5A50" alt="http://www.codeproject.com/images/minus.gif">Collapse<o:p></o:p></p> <pre style='margin-left:.5in' id=pre8><span class=code-keyword><</span><span class=code-leadattribute>sessionState</span> <span class=code-attribute>mode</span><span class=code-keyword>='Off'/></span><o:p></o:p></pre> <ul type=disc> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l5 level1 lfo5'>To disable session state for all applications on your Web server, use the following element in the <em><span style='font-family:"Calibri","sans-serif"'>Machine.config</span></em> file: <o:p></o:p></li> </ul> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; margin-left:.5in'><img border=0 width=9 height=9 id=preimg9 src="cid:image002.gif@01CAF5B0.DF2B5A50" alt="http://www.codeproject.com/images/minus.gif">Collapse<o:p></o:p></p> <pre style='margin-left:.5in' id=pre9><span class=code-keyword><</span><span class=code-leadattribute>sessionState</span> <span class=code-attribute>mode</span><span class=code-keyword>='Off'/></span><o:p></o:p></pre> <h2>6. Use Server.Transfer<o:p></o:p></h2> <p>Use the <code><span style='font-size:10.0pt'>Server.Transfer</span></code> method to redirect between pages in the same application. Using this method in a page, with <code><span style='font-size:10.0pt'>Server.Transfer </span></code>syntax, avoids unnecessary client-side redirection. Consider Using <code><span style='font-size:10.0pt'>Server.Transfer </span></code>Instead of <code><span style='font-size:10.0pt'>Response.Redirect</span></code>. However, you cannot always just replace <code><span style='font-size:10.0pt'>Response.Redirect </span></code>calls with <code><span style='font-size:10.0pt'>Server.Transfer</span></code>. If you need authentication and authorization checks during redirection, use <code><span style='font-size:10.0pt'>Response.Redirect </span></code>instead of <code><span style='font-size:10.0pt'>Server.Transfer </span></code>because the two mechanisms are not equivalent. When you use <code><span style='font-size:10.0pt'>Response.Redirect</span></code>, ensure you use the overloaded method that accepts a Boolean second parameter, and pass a value of <span class=code-keyword><span style='font-size:10.0pt; font-family:"Courier New"'>false</span></span><code><span style='font-size: 10.0pt'> </span></code>to ensure an internal <code><span style='font-size:10.0pt'>exception </span></code>is not raised. Also note that you can only use <code><span style='font-size:10.0pt'>Server.Transfer </span></code>to transfer control to pages in the same application. To transfer to pages in other applications, you must use <code><span style='font-size:10.0pt'>Response.Redirect</span></code>.<o:p></o:p></p> <h2>7. Use server controls when appropriate and avoid creating deeply nested controls<o:p></o:p></h2> <p>The HTTP protocol is stateless; however, server controls provide a rich programming model that manage state between page requests by using <code><span style='font-size:10.0pt'>ViewState</span></code>. However nothing comes for free, server controls require a fixed amount of processing to establish the control and all of its child controls. This makes server controls relatively expensive compared to HTML controls or possibly static text. When you do not need rich interaction, replace server controls with an inline representation of the user interface that you want to present. It is better to replace a server control if: <o:p></o:p></p> <ul type=disc> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l3 level1 lfo6'>You do not need to retain state across postbacks<o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l3 level1 lfo6'>The data that appears in the control is static or control displays read-only data <o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l3 level1 lfo6'>You do not need programmatic access to the control on the server-side<o:p></o:p></li> </ul> <p>Alternatives to server controls include simple rendering, HTML elements, inline <code><span style='font-size:10.0pt'>Response.Write </span></code>calls, and raw inline angle brackets (<span class=code-pagedirective><span style='font-size:10.0pt;font-family:"Courier New"'><%</span></span><code><span style='font-size:10.0pt'> </span></code><span class=code-pagedirective><span style='font-size:10.0pt;font-family:"Courier New"'>%></span></span>). It is essential to balance your tradeoffs. Avoid over optimization if the overhead is acceptable and if your application is within the limits of its performance objectives. <o:p></o:p></p> <p>Deeply nested hierarchies of controls compound the cost of creating a server control and its child controls. Deeply nested hierarchies create extra processing that could be avoided by using a different design that uses inline controls, or by using a flatter hierarchy of server controls. This is especially important when you use controls such as <code><span style='font-size:10.0pt'>Repeater</span></code>, <code><span style='font-size: 10.0pt'>DataList</span></code>, and <code><span style='font-size:10.0pt'>DataGrid </span></code>because they create additional child controls in the container. <o:p></o:p></p> <h2>8. Choose the data viewing control appropriate for your solution<o:p></o:p></h2> <p>Depending on how you choose to display data in a Web Forms page, there are often significant tradeoffs between convenience and performance. Always compare the pros and cons of controls before you use them in your application. For example, you can choose any of these three controls (<code><span style='font-size:10.0pt'>DataGrid</span></code>, <code><span style='font-size: 10.0pt'>DataList </span></code>and <code><span style='font-size:10.0pt'>Repeater</span></code>) to display data, it's your job to find out which control will provide you maximum benefit. The <code><span style='font-size:10.0pt'>DataGrid </span></code>control can be a quick and easy way to display data, but it is frequently the most expensive in terms of performance. Rendering the data yourself by generating the appropriate HTML may work in some simple cases, but customization and browser targeting can quickly offset the extra work involved. A <code><span style='font-size:10.0pt'>Repeater </span></code>Web server control is a compromise between convenience and performance. It is efficient, customizable, and programmable. <o:p></o:p></p> <h2>9. Optimize code and exception handling<o:p></o:p></h2> <p>To optimize expensive loops, use <code><span style='font-size:10.0pt'>For </span></code>instead of <code><span style='font-size:10.0pt'>ForEach </span></code>in performance-critical code paths. Also do not rely on <code><span style='font-size:10.0pt'>exception</span></code>s in your code and write code that avoids <code><span style='font-size:10.0pt'>exception</span></code>s. Since <code><span style='font-size:10.0pt'>exception</span></code>s cause performance to suffer significantly, you should never use them as a way to control normal program flow. If it is possible to detect in code a condition that would cause an <code><span style='font-size:10.0pt'>exception</span></code>, do so. Do not catch the <code><span style='font-size:10.0pt'>exception </span></code>itself before you handle that condition. Do not use <code><span style='font-size:10.0pt'>exception</span></code>s to control logic. A database connection that fails to open is an <code><span style='font-size:10.0pt'>exception </span></code>but a user who mistypes his password is simply a condition that needs to be handled. Common scenarios include checking for <code><span style='font-size:10.0pt'>null</span></code>, assigning a value to a <span class=code-sdkkeyword><span style='font-size:10.0pt; font-family:"Courier New"'>String</span></span><code><span style='font-size: 10.0pt'> </span></code>that will be parsed into a numeric value, or checking for specific values before applying math operations. The following example demonstrates code that could cause an <code><span style='font-size:10.0pt'>exception </span></code>and code that tests for a condition. Both produce the same result. <o:p></o:p></p> <p class=MsoNormal><img border=0 width=9 height=9 id=preimg10 src="cid:image002.gif@01CAF5B0.DF2B5A50" alt="http://www.codeproject.com/images/minus.gif">Collapse<o:p></o:p></p> <pre id=pre10><span class=code-comment>'Unnecessary use of exception<o:p></o:p></span></pre><pre><o:p> </o:p></pre><pre> <span class=code-keyword>Try</span><o:p></o:p></pre><pre> value = <span class=code-digit>100</span> / number<o:p></o:p></pre><pre><span class=code-keyword>Catch</span> ex <span class=code-keyword>As</span> Exception<o:p></o:p></pre><pre> value = <span class=code-digit>0</span><o:p></o:p></pre><pre><span class=code-keyword>End</span> <span class=code-keyword>Try</span><o:p></o:p></pre><pre><o:p> </o:p></pre><pre><span class=code-comment>' Recommended code<o:p></o:p></span></pre><pre><o:p> </o:p></pre><pre><span class=code-keyword>If</span> <span class=code-keyword>Not</span> number = <span class=code-digit>0</span> <span class=code-keyword>Then</span><o:p></o:p></pre><pre> value = <span class=code-digit>100</span> / number<o:p></o:p></pre><pre><span class=code-keyword>Else</span><o:p></o:p></pre><pre> value = <span class=code-digit>0</span><o:p></o:p></pre><pre><span class=code-keyword>End</span> <span class=code-keyword>If</span><o:p></o:p></pre> <p>Check for <code><span style='font-size:10.0pt'>null </span></code>values. If it is possible for an object to be <code><span style='font-size:10.0pt'>null</span></code>, check to make sure it is not <code><span style='font-size:10.0pt'>null</span></code>, rather then throwing an <code><span style='font-size:10.0pt'>exception</span></code>. This commonly occurs when you retrieve items from <code><span style='font-size: 10.0pt'>ViewState</span></code>, session state, application state, or cache objects as well as query string and form field variables. For example, do not use the following code to access session state information. <o:p></o:p></p> <p class=MsoNormal><img border=0 width=9 height=9 id=preimg11 src="cid:image002.gif@01CAF5B0.DF2B5A50" alt="http://www.codeproject.com/images/minus.gif">Collapse<o:p></o:p></p> <pre id=pre11><span class=code-comment>'Unnecessary use of exception<o:p></o:p></span></pre><pre><o:p> </o:p></pre><pre><span class=code-keyword>Try</span><o:p></o:p></pre><pre>value = HttpContext.Current.Session(<span class=code-string>"Value"</span>).ToString<o:p></o:p></pre><pre><span class=code-keyword>Catch</span> ex <span class=code-keyword>As</span> Exception<o:p></o:p></pre><pre>Response.Redirect(<span class=code-string>"Main.aspx"</span>, <span class=code-keyword>False</span>)<o:p></o:p></pre><pre><span class=code-keyword>End</span> <span class=code-keyword>Try</span><o:p></o:p></pre><pre> <o:p></o:p></pre><pre><span class=code-comment>'Recommended code <o:p></o:p></span></pre><pre><o:p> </o:p></pre><pre><span class=code-keyword>If</span> <span class=code-keyword>Not</span> HttpContext.Current.Session(<span class=code-string>"Value"</span>) <span class=code-keyword>Is</span> <span class=code-keyword>Nothing</span> <span class=code-keyword>Then</span><o:p></o:p></pre><pre>value = HttpContext.Current.Session(<span class=code-string>"Value"</span>).ToString<o:p></o:p></pre><pre><span class=code-keyword>Else</span><o:p></o:p></pre><pre>Response.Redirect(<span class=code-string>"Main.aspx"</span>, <span class=code-keyword>False</span>)<o:p></o:p></pre><pre><span class=code-keyword>End</span> <span class=code-keyword>If</span><o:p></o:p></pre> <h2>10. Use a DataReader for fast and efficient data binding<o:p></o:p></h2> <p>Use a <code><span style='font-size:10.0pt'>DataReader </span></code>object if you do not need to cache data, if you are displaying read-only data, and if you need to load data into a control as quickly as possible. The <code><span style='font-size:10.0pt'>DataReader </span></code>is the optimum choice for retrieving read-only data in a forward-only manner. Loading the data into a <code><span style='font-size:10.0pt'>DataSet </span></code>object and then binding the <code><span style='font-size:10.0pt'>DataSet </span></code>to the control moves the data twice. This method also incurs the relatively significant expense of constructing a <code><span style='font-size:10.0pt'>DataSet</span></code>. In addition, when you use the <code><span style='font-size:10.0pt'>DataReader</span></code>, you can use the specialized type-specific methods to retrieve the data for better performance.<o:p></o:p></p> <h2>11. Use paging efficiently<o:p></o:p></h2> <p>Allowing users to request and retrieve more data than they can consume puts an unnecessary strain on your application resources. This unnecessary strain causes increased CPU utilization, increased memory consumption, and decreased response times. This is especially true for clients that have a slow connection speed. From a usability standpoint, most users do not want to see thousands of rows presented as a single unit. Implement a paging solution that retrieves only the desired data from the database and reduces back-end work on the database. You should optimize the number of rows returned by the Database Server to the middle-tier web-server. For more information <a href="http://weblogs.asp.net/scottgu/archive/2006/01/01/434314.aspx">read this article </a>to implement paging at the Database level. If you are using SQL Server 2000, please also look at <a href="http://www.codeproject.com/aspnet/PagingLarge.asp">this article.</a><o:p></o:p></p> <h2>12. Explicitly Dispose or Close all the resources<o:p></o:p></h2> <p>To guarantee resources are cleaned up when an exception occurs, use a <span class=code-keyword><span style='font-size:10.0pt;font-family:"Courier New"'>try</span></span>/<span class=code-keyword><span style='font-size:10.0pt;font-family:"Courier New"'>finally</span></span><code><span style='font-size:10.0pt'> </span></code>block. Close the resources in the <span class=code-keyword><span style='font-size:10.0pt;font-family:"Courier New"'>finally</span></span><code><span style='font-size:10.0pt'> </span></code>clause. Using a <span class=code-keyword><span style='font-size:10.0pt;font-family:"Courier New"'>try</span></span>/<span class=code-keyword><span style='font-size:10.0pt;font-family:"Courier New"'>finally</span></span><code><span style='font-size:10.0pt'> </span></code>block ensures that resources are disposed even if an <code><span style='font-size:10.0pt'>exception </span></code>occurs. Open your connection just before needing it, and close it as soon as you're done with it. Your motto should always be "get in, get/save data, get out." If you use different objects, make sure you call the <code><span style='font-size:10.0pt'>Dispose </span></code>method of the object or the <code><span style='font-size:10.0pt'>Close </span></code>method if one is provided. Failing to call <code><span style='font-size:10.0pt'>Close </span></code>or <code><span style='font-size:10.0pt'>Dispose </span></code>prolongs the life of the object in memory long after the client stops using it. This defers the cleanup and can contribute to memory pressure. Database connection and files are examples of shared resources that should be explicitly closed. <o:p></o:p></p> <p class=MsoNormal><img border=0 width=9 height=9 id=preimg12 src="cid:image002.gif@01CAF5B0.DF2B5A50" alt="http://www.codeproject.com/images/minus.gif">Collapse<o:p></o:p></p> <pre id=pre12><span class=code-keyword>Try</span><o:p></o:p></pre><pre>_con.Open()<o:p></o:p></pre><pre><span class=code-keyword>Catch</span> ex <span class=code-keyword>As</span> Exception<o:p></o:p></pre><pre><span class=code-keyword>Throw</span> ex<o:p></o:p></pre><pre><span class=code-keyword>Finally</span><o:p></o:p></pre><pre><span class=code-keyword>If</span> <span class=code-keyword>Not</span> _con <span class=code-keyword>Is</span> <span class=code-keyword>Nothing</span> <span class=code-keyword>Then</span><o:p></o:p></pre><pre>_con.Close()<o:p></o:p></pre><pre><span class=code-keyword>End</span> <span class=code-keyword>If</span><o:p></o:p></pre><pre><span class=code-keyword>End</span> <span class=code-keyword>Try</span><o:p></o:p></pre> <h2>13. Disable tracing and debugging<o:p></o:p></h2> <p>Before you deploy your application, disable tracing and debugging. Tracing and debugging may cause performance issues. Tracing and debugging are not recommended while your application is running in production. You can disable tracing and debugging in the <em>Machine.config</em> and <em>Web.config</em> using the syntax below:<o:p></o:p></p> <p class=MsoNormal><img border=0 width=9 height=9 id=preimg13 src="cid:image002.gif@01CAF5B0.DF2B5A50" alt="http://www.codeproject.com/images/minus.gif">Collapse<o:p></o:p></p> <pre id=pre13><span class=code-keyword><</span><span class=code-leadattribute>configuration</span><span class=code-keyword>></span><o:p></o:p></pre><pre> <span class=code-keyword><</span><span class=code-leadattribute>system.web</span><span class=code-keyword>></span><o:p></o:p></pre><pre> <span class=code-keyword><</span><span class=code-leadattribute>trace</span> <span class=code-attribute>enabled</span><span class=code-keyword>="false"</span> <span class=code-attribute>pageOutput</span><span class=code-keyword>="false"</span> <span class=code-keyword>/></span><o:p></o:p></pre><pre> <span class=code-keyword><</span><span class=code-leadattribute>compilation</span> <span class=code-attribute>debug</span><span class=code-keyword>="false"</span> <span class=code-keyword>/></span><o:p></o:p></pre><pre> <span class=code-keyword></</span><span class=code-leadattribute>system.web</span><span class=code-keyword>></span><o:p></o:p></pre><pre><span class=code-keyword></</span><span class=code-leadattribute>configuration</span><span class=code-keyword>></span><o:p></o:p></pre> <h2>14. Precompile pages and disable AutoEventWireup<o:p></o:p></h2> <p>By precompiled pages, users do not have to experience the batch compile of your ASP.NET files; it will increase the performance that your users will experience. <o:p></o:p></p> <p>In addition, setting the <code><span style='font-size:10.0pt'>AutoEventWireup </span></code>attribute to <span class=code-keyword><span style='font-size: 10.0pt;font-family:"Courier New"'>false</span></span><code><span style='font-size:10.0pt'> </span></code>in the <em>Machine.config</em> file means that the page will not match method names to events and hook them up (for example, <code><span style='font-size:10.0pt'>Page_Load</span></code>). If page developers want to use these events, they will need to override the methods in the base class (for example, they will need to override <code><span style='font-size:10.0pt'>Page.OnLoad </span></code>for the page load event instead of using a <code><span style='font-size:10.0pt'>Page_Load </span></code>method). If you disable <code><span style='font-size:10.0pt'>AutoEventWireup</span></code>, your pages will get a slight performance boost by leaving the event wiring to the page author instead of performing it automatically. <o:p></o:p></p> <h2>15. Use stored procedures and indexes<o:p></o:p></h2> <p>In most cases you can get an additional performance boost by using compiled stored procedures instead of ad hoc queries. <o:p></o:p></p> <p>Make sure you index your tables, and choose your indexes wisely. Try using Index Tuning Wizard and have it report to you what it thinks the best candidates for indexes would be. You don't have to follow all of its suggestions, but it may reveal things about your structure or data that will help you choose more appropriate indexes. <o:p></o:p></p> <ul type=disc> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l12 level1 lfo7'>In SQL Server Management Studio (SQL Server 2005), highlight your query. Now from the Query menu, click Analyze Query in Database Engine Tuning Advisor. <o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l12 level1 lfo7'>You can do something similar in SQL Server 2000 to run the index tuning wizard? In Query Analyzer, highlight your query. From the Query menu, click Index Tuning Wizard. <o:p></o:p></li> </ul> <p class=MsoNormal><o:p> </o:p></p> <h2><a href="http://davidhayden.com/blog/dave/archive/2005/09/29/2492.aspx">ASP.NET 2.0 Security Best Practices - Must Read Article on MSDN</a> <o:p></o:p></h2> <p><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>I printed out this fantastic article on MSDN, called <strong><span style='font-family: "Verdana","sans-serif"'>Security Practices: ASP.NET 2.0 Security Practices at a Glance</span></strong>. If you do nothing else this weekend, I recommend you </span><a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag2/html/PAGPractices0001.asp" target="_blank"><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>check out the article here</span></a><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'> and see where you can improve the security of your applications.</span><o:p></o:p></p> <p><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>Here are just a few of the items worth noting. I hope to go into them all in more detail in future posts:</span><o:p></o:p></p> <p> <o:p></o:p></p> <p><strong><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>Use PrincipalPermission to Demand Role-Base Security</span></strong><o:p></o:p></p> <p><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>[PrincipalPermission(SecurityAction.Demand, Role="Admin")]<br> public class AdminOnlyPage : BasePage<br> {<br> // ...<br> }</span><o:p></o:p></p> <p> <o:p></o:p></p> <p><strong><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>Securing a Particular Directory in ASP.NET for Specific Roles</span></strong><o:p></o:p></p> <p><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'><location path="Secure" ><br> <system.web><br> <authorization><br> <deny users="?" /><br> </authorization><br> </system.web><br> </location></span><o:p></o:p></p> <p> <o:p></o:p></p> <p><strong><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>Prevent SQL Injection by Using SqlParameters</span></strong><o:p></o:p></p> <p><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>using System.Data;<br> using System.Data.SqlClient;<br> <br> using (SqlConnection connection = new SqlConnection(connectionString))<br> {<br> DataSet userDataset = new DataSet();<br> SqlDataAdapter myCommand = new SqlDataAdapter( <br> "LoginStoredProcedure", connection);<br> myCommand.SelectCommand.CommandType = CommandType.StoredProcedure;<br> myCommand.SelectCommand.Parameters.Add("@au_id", SqlDbType.VarChar, 11);<br> myCommand.SelectCommand.Parameters["@au_id"].Value = SSN.Text;<br> <br> myCommand.Fill(userDataset);<br> }</span><o:p></o:p></p> <p><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'> </span><o:p></o:p></p> <p><strong><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>Turn On Custom Errors To Keep Errors Private</span></strong><o:p></o:p></p> <p><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'><customErrors mode="On" defaultRedirect="YourErrorPage.htm" /></span><o:p></o:p></p> <p><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'><br> </span><o:p></o:p></p> <p><strong><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>Create a Global Error Handler for Your ASP.NET Applications</span></strong><o:p></o:p></p> <p><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'><%@ Application Language="C#" %><br> <%@ Import Namespace="System.Diagnostics" %><br> <br> <script language="C#" runat="server"><br> void Application_Error(object sender, EventArgs e)<br> {<br> //get reference to the source of the exception chain<br> Exception ex = Server.GetLastError().GetBaseException();<br> <br> //log the details of the exception and page state to the<br> //Event Log<br> EventLog.WriteEntry("My Web Application",<br> "MESSAGE: " + ex.Message + <br> "\nSOURCE: " + ex.Source +<br> "\nFORM: " + Request.Form.ToString() + <br> "\nQUERYSTRING: " + Request.QueryString.ToString() +<br> "\nTARGETSITE: " + ex.TargetSite +<br> "\nSTACKTRACE: " + ex.StackTrace, <br> EventLogEntryType.Error);<br> <br> //Optional email or other notification here...<br> }<br> </script></span><o:p></o:p></p> <p><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'><br> </span><o:p></o:p></p> <p><strong><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>Prevent Cross-Site Scripting Using HtmlEncode and UrlEncode</span></strong><o:p></o:p></p> <p><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>Response.Write(HttpUtility.HtmlEncode(Request.Form["name"]));</span><o:p></o:p></p> <p><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>Response.Write(HttpUtility.UrlEncode(urlString));</span><o:p></o:p></p> <p><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>// Encode the string input from the HTML input text field<br> StringBuilder sb = new StringBuilder(HttpUtility.HtmlEncode(htmlInputTxt.Text));<br> // Selectively allow <b><b> </b>and <i><br> sb.Replace("&lt;b&gt;", "<b>");<br> sb.Replace("&lt;/b&gt;", "</b>");<br> sb.Replace("&lt;i&gt;", "<i>");<br> sb.Replace("&lt;/i&gt;", "</i>");</span><o:p></o:p></p> <p><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'><br> </span><o:p></o:p></p> <p><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>The article contains a lot of other great words of wisdom when securing your applications. I recommend reading the article this weekend and implementing those that make sense in your applications.</span><o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal><o:p> </o:p></p> <h4><a href="http://odetocode.com/Blogs/scott/archive/2006/01/09/encrypting-custom-configuration-sections.aspx" title="Title of this entry.">Encrypting Custom Configuration Sections</a><o:p></o:p></h4> <p>The ASP.NET IIS Registration Tool (Aspnet_regiis.exe) can <a href="http://msdn2.microsoft.com/en-us/library/zhhddkxy.aspx">encrypt and decrypt</a> sections of web.config. There is no special code required in an application, as ASP.NET 2.0 will magically decrypt sections at runtime. <o:p></o:p></p> <p>The tool and runtime can also work together to encrypt and decrypt custom configuration sections. So if I have the following in web.config: <o:p></o:p></p> <p class=MsoNormal style='background:#D3D3BD'><span style='font-size:8.0pt; font-family:"Courier New";color:blue'><</span><span style='font-size:8.0pt; font-family:"Courier New";color:maroon'>configSections</span><span style='font-size:8.0pt;font-family:"Courier New";color:blue'>><br> <</span><span style='font-size:8.0pt;font-family:"Courier New"; color:maroon'>section</span><span style='font-size:8.0pt;font-family:"Courier New"; color:blue'> <br> </span><span style='font-size:8.0pt; font-family:"Courier New";color:red'>name</span><span style='font-size:8.0pt; font-family:"Courier New";color:blue'>=</span><span style='font-size:8.0pt; font-family:"Courier New";color:black'>"</span><span style='font-size: 8.0pt;font-family:"Courier New";color:blue'>sampleSection</span><span style='font-size:8.0pt;font-family:"Courier New";color:black'>"</span><span style='font-size:8.0pt;font-family:"Courier New";color:blue'> <br> </span><span style='font-size:8.0pt; font-family:"Courier New";color:red'>type</span><span style='font-size:8.0pt; font-family:"Courier New";color:blue'>=</span><span style='font-size:8.0pt; font-family:"Courier New";color:black'>"</span><span style='font-size: 8.0pt;font-family:"Courier New";color:blue'>System.Configuration.SingleTagSectionHandler</span><span style='font-size:8.0pt;font-family:"Courier New";color:black'>"</span><span style='font-size:8.0pt;font-family:"Courier New";color:blue'> <br> /><br> </</span><span style='font-size:8.0pt;font-family:"Courier New";color:maroon'>configSections</span><span style='font-size:8.0pt;font-family:"Courier New";color:blue'>><br> <br> <</span><span style='font-size:8.0pt;font-family:"Courier New";color:maroon'>MySecrets<br> </span><span style='font-size:8.0pt;font-family:"Courier New";color:blue'> </span><span style='font-size:8.0pt;font-family:"Courier New";color:red'>FavoriteMusic</span><span style='font-size:8.0pt;font-family:"Courier New";color:blue'>=</span><span style='font-size:8.0pt;font-family:"Courier New";color:black'>"</span><span style='font-size:8.0pt;font-family:"Courier New";color:blue'>Disco</span><span style='font-size:8.0pt;font-family:"Courier New";color:black'>"</span><span style='font-size:8.0pt;font-family:"Courier New";color:blue'> <br> </span><span style='font-size:8.0pt;font-family:"Courier New"; color:red'>FavoriteLanguage</span><span style='font-size:8.0pt;font-family: "Courier New";color:blue'>=</span><span style='font-size:8.0pt;font-family: "Courier New";color:black'>"</span><span style='font-size:8.0pt; font-family:"Courier New";color:blue'>COBOL</span><span style='font-size:8.0pt; font-family:"Courier New";color:black'>"</span><span style='font-size: 8.0pt;font-family:"Courier New";color:blue'> <br> </span><span style='font-size:8.0pt;font-family:"Courier New"; color:red'>DreamJob</span><span style='font-size:8.0pt;font-family:"Courier New"; color:blue'>=</span><span style='font-size:8.0pt;font-family:"Courier New"; color:black'>"</span><span style='font-size:8.0pt;font-family:"Courier New"; color:blue'>Dancing in the opening ceremonies of the Olympics</span><span style='font-size:8.0pt;font-family:"Courier New";color:black'>"</span><span style='font-size:8.0pt;font-family:"Courier New";color:blue'> <br> /></span><span style='font-size:8.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p>All I need to do from the command line, is: <o:p></o:p></p> <p class=MsoNormal style='background:#D3D3BD'><span style='font-size:8.0pt; font-family:"Courier New"'>aspnet_regiis -pef MySecrets . <o:p></o:p></span></p> <p>It’s easier than a double pirouette… <o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal><o:p> </o:p></p> <h2>Best Practices for Speeding Up Your Web Site<o:p></o:p></h2> <p>The Exceptional Performance team has identified a number of best practices for making web pages fast. The list includes 35 best practices divided into 7 categories.<o:p></o:p></p> <p class=inlprompt>Filter by category:<o:p></o:p></p> <ul type=disc> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l18 level1 lfo8'>Content<o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l18 level1 lfo8'>Server<o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l18 level1 lfo8'>Cookie<o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l18 level1 lfo8'>CSS<o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l18 level1 lfo8'>JavaScript<o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l18 level1 lfo8'>Images<o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l18 level1 lfo8'>Mobile<o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l18 level1 lfo8'>All<o:p></o:p></li> </ul> <h3 id="num_http">Minimize HTTP Requests<o:p></o:p></h3> <p class=date>tag: content<o:p></o:p></p> <p>80% of the end-user response time is spent on the front-end. Most of this time is tied up in downloading all the components in the page: images, stylesheets, scripts, Flash, etc. Reducing the number of components in turn reduces the number of HTTP requests required to render the page. This is the key to faster pages. <o:p></o:p></p> <p>One way to reduce the number of components in the page is to simplify the page's design. But is there a way to build pages with richer content while also achieving fast response times? Here are some techniques for reducing the number of HTTP requests, while still supporting rich page designs.<o:p></o:p></p> <p><strong>Combined files</strong> are a way to reduce the number of HTTP requests by combining all scripts into a single script, and similarly combining all CSS into a single stylesheet. Combining files is more challenging when the scripts and stylesheets vary from page to page, but making this part of your release process improves response times.<o:p></o:p></p> <p><a href="http://alistapart.com/articles/sprites"><strong><span style='color:blue'>CSS Sprites</span></strong></a> are the preferred method for reducing the number of image requests. Combine your background images into a single image and use the CSS <code><span style='font-size:10.0pt'>background-image</span></code> and <code><span style='font-size:10.0pt'>background-position</span></code> properties to display the desired image segment.<o:p></o:p></p> <p><a href="http://www.w3.org/TR/html401/struct/objects.html#h-13.6"><strong><span style='color:blue'>Image maps</span></strong></a> combine multiple images into a single image. The overall size is about the same, but reducing the number of HTTP requests speeds up the page. Image maps only work if the images are contiguous in the page, such as a navigation bar. Defining the coordinates of image maps can be tedious and error prone. Using image maps for navigation is not accessible too, so it's not recommended.<o:p></o:p></p> <p><strong>Inline images</strong> use the <a href="http://tools.ietf.org/html/rfc2397"><code><span style='font-size:10.0pt; color:blue'>data:</span></code> URL scheme</a> to embed the image data in the actual page. This can increase the size of your HTML document. Combining inline images into your (cached) stylesheets is a way to reduce HTTP requests and avoid increasing the size of your pages. Inline images are not yet supported across all major browsers.<o:p></o:p></p> <p>Reducing the number of HTTP requests in your page is the place to start. This is the most important guideline for improving performance for first time visitors. As described in Tenni Theurer's blog post <a href="http://yuiblog.com/blog/2007/01/04/performance-research-part-2/">Browser Cache Usage - Exposed!</a>, 40-60% of daily visitors to your site come in with an empty cache. Making your page fast for these first time visitors is key to a better user experience.<o:p></o:p></p> <p><a href="http://developer.yahoo.com/performance/rules.html#page-nav">top</a> | <a href="http://developer.yahoo.net/blog/archives/2007/04/rule_1_make_few.html">discuss this rule</a><o:p></o:p></p> <h3 id=cdn>Use a Content Delivery Network<o:p></o:p></h3> <p class=date>tag: server<o:p></o:p></p> <p>The user's proximity to your web server has an impact on response times. Deploying your content across multiple, geographically dispersed servers will make your pages load faster from the user's perspective. But where should you start?<o:p></o:p></p> <p>As a first step to implementing geographically dispersed content, don't attempt to redesign your web application to work in a distributed architecture. Depending on the application, changing the architecture could include daunting tasks such as synchronizing session state and replicating database transactions across server locations. Attempts to reduce the distance between users and your content could be delayed by, or never pass, this application architecture step. <o:p></o:p></p> <p>Remember that 80-90% of the end-user response time is spent downloading all the components in the page: images, stylesheets, scripts, Flash, etc. This is the <em>Performance Golden Rule</em>. Rather than starting with the difficult task of redesigning your application architecture, it's better to first disperse your static content. This not only achieves a bigger reduction in response times, but it's easier thanks to content delivery networks.<o:p></o:p></p> <p>A content delivery network (CDN) is a collection of web servers distributed across multiple locations to deliver content more efficiently to users. The server selected for delivering content to a specific user is typically based on a measure of network proximity. For example, the server with the fewest network hops or the server with the quickest response time is chosen.<o:p></o:p></p> <p>Some large Internet companies own their own CDN, but it's cost-effective to use a CDN service provider, such as <a href="http://www.akamai.com/">Akamai Technologies</a>, <a href="http://www.mirror-image.com/">Mirror Image Internet</a>, or <a href="http://www.limelightnetworks.com/">Limelight Networks</a>. For start-up companies and private web sites, the cost of a CDN service can be prohibitive, but as your target audience grows larger and becomes more global, a CDN is necessary to achieve fast response times. At Yahoo!, properties that moved static content off their application web servers to a CDN improved end-user response times by 20% or more. Switching to a CDN is a relatively easy code change that will dramatically improve the speed of your web site.<o:p></o:p></p> <p><a href="http://developer.yahoo.com/performance/rules.html#page-nav">top</a> | <a href="http://developer.yahoo.net/blog/archives/2007/04/high_performanc_1.html">discuss this rule</a><o:p></o:p></p> <h3 id=expires>Add an Expires or a Cache-Control Header<o:p></o:p></h3> <p class=date>tag: server<o:p></o:p></p> <p>There are two aspects to this rule:<o:p></o:p></p> <ul type=disc> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l10 level1 lfo9'>For static components: implement "Never expire" policy by setting far future <code><span style='font-size: 10.0pt'>Expires</span></code> header<o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l10 level1 lfo9'>For dynamic components: use an appropriate <code><span style='font-size:10.0pt'>Cache-Control</span></code> header to help the browser with conditional requests<o:p></o:p></li> </ul> <p class=MsoNormal><o:p> </o:p></p> <p>Web page designs are getting richer and richer, which means more scripts, stylesheets, images, and Flash in the page. A first-time visitor to your page may have to make several HTTP requests, but by using the Expires header you make those components cacheable. This avoids unnecessary HTTP requests on subsequent page views. Expires headers are most often used with images, but they should be used on <em>all</em> components including scripts, stylesheets, and Flash components.<o:p></o:p></p> <p>Browsers (and proxies) use a cache to reduce the number and size of HTTP requests, making web pages load faster. A web server uses the Expires header in the HTTP response to tell the client how long a component can be cached. This is a far future Expires header, telling the browser that this response won't be stale until April 15, 2010. <o:p></o:p></p> <pre> Expires: Thu, 15 Apr 2010 20:00:00 GMT<o:p></o:p></pre> <p class=MsoNormal><o:p> </o:p></p> <p>If your server is Apache, use the ExpiresDefault directive to set an expiration date relative to the current date. This example of the ExpiresDefault directive sets the Expires date 10 years out from the time of the request.<o:p></o:p></p> <pre> ExpiresDefault "access plus 10 years"<o:p></o:p></pre> <p class=MsoNormal><o:p> </o:p></p> <p>Keep in mind, if you use a far future Expires header you have to change the component's filename whenever the component changes. At Yahoo! we often make this step part of the build process: a version number is embedded in the component's filename, for example, yahoo_2.0.6.js.<o:p></o:p></p> <p>Using a far future Expires header affects page views only after a user has already visited your site. It has no effect on the number of HTTP requests when a user visits your site for the first time and the browser's cache is empty. Therefore the impact of this performance improvement depends on how often users hit your pages with a primed cache. (A "primed cache" already contains all of the components in the page.) We <a href="http://yuiblog.com/blog/2007/01/04/performance-research-part-2/">measured this at Yahoo!</a> and found the number of page views with a primed cache is 75-85%. By using a far future Expires header, you increase the number of components that are cached by the browser and re-used on subsequent page views without sending a single byte over the user's Internet connection.<o:p></o:p></p> <p><a href="http://developer.yahoo.com/performance/rules.html#page-nav">top</a> | <a href="http://developer.yahoo.net/blog/archives/2007/05/high_performanc_2.html">discuss this rule</a><o:p></o:p></p> <h3 id=gzip>Gzip Components<o:p></o:p></h3> <p class=date>tag: server<o:p></o:p></p> <p>The time it takes to transfer an HTTP request and response across the network can be significantly reduced by decisions made by front-end engineers. It's true that the end-user's bandwidth speed, Internet service provider, proximity to peering exchange points, etc. are beyond the control of the development team. But there are other variables that affect response times. Compression reduces response times by reducing the size of the HTTP response.<o:p></o:p></p> <p>Starting with HTTP/1.1, web clients indicate support for compression with the Accept-Encoding header in the HTTP request.<o:p></o:p></p> <pre> Accept-Encoding: gzip, deflate<o:p></o:p></pre> <p class=MsoNormal><o:p> </o:p></p> <p>If the web server sees this header in the request, it may compress the response using one of the methods listed by the client. The web server notifies the web client of this via the Content-Encoding header in the response.<o:p></o:p></p> <pre> Content-Encoding: gzip<o:p></o:p></pre> <p class=MsoNormal><o:p> </o:p></p> <p>Gzip is the most popular and effective compression method at this time. It was developed by the GNU project and standardized by <a href="http://www.ietf.org/rfc/rfc1952.txt">RFC 1952</a>. The only other compression format you're likely to see is deflate, but it's less effective and less popular. <o:p></o:p></p> <p>Gzipping generally reduces the response size by about 70%. Approximately 90% of today's Internet traffic travels through browsers that claim to support gzip. If you use Apache, the module configuring gzip depends on your version: Apache 1.3 uses <a href="http://sourceforge.net/projects/mod-gzip/">mod_gzip</a> while Apache 2.x uses <a href="http://httpd.apache.org/docs/2.0/mod/mod_deflate.html">mod_deflate</a>. <o:p></o:p></p> <p>There are known issues with browsers and proxies that may cause a mismatch in what the browser expects and what it receives with regard to compressed content. Fortunately, these edge cases are dwindling as the use of older browsers drops off. The Apache modules help out by adding appropriate Vary response headers automatically. <o:p></o:p></p> <p>Servers choose what to gzip based on file type, but are typically too limited in what they decide to compress. Most web sites gzip their HTML documents. It's also worthwhile to gzip your scripts and stylesheets, but many web sites miss this opportunity. In fact, it's worthwhile to compress any text response including XML and JSON. Image and PDF files should not be gzipped because they are already compressed. Trying to gzip them not only wastes CPU but can potentially increase file sizes. <o:p></o:p></p> <p>Gzipping as many file types as possible is an easy way to reduce page weight and accelerate the user experience.<o:p></o:p></p> <p><a href="http://developer.yahoo.com/performance/rules.html#page-nav">top</a> | <a href="http://developer.yahoo.net/blog/archives/2007/07/high_performanc_3.html">discuss this rule</a><o:p></o:p></p> <h3 id="css_top">Put Stylesheets at the Top<o:p></o:p></h3> <p class=date>tag: css<o:p></o:p></p> <p>While researching performance at Yahoo!, we discovered that moving stylesheets to the document HEAD makes pages <em>appear</em> to be loading faster. This is because putting stylesheets in the HEAD allows the page to render progressively. <o:p></o:p></p> <p>Front-end engineers that care about performance want a page to load progressively; that is, we want the browser to display whatever content it has as soon as possible. This is especially important for pages with a lot of content and for users on slower Internet connections. The importance of giving users visual feedback, such as progress indicators, has been well researched and <a href="http://www.useit.com/papers/responsetime.html">documented</a>. In our case the HTML page is the progress indicator! When the browser loads the page progressively the header, the navigation bar, the logo at the top, etc. all serve as visual feedback for the user who is waiting for the page. This improves the overall user experience.<o:p></o:p></p> <p>The problem with putting stylesheets near the bottom of the document is that it prohibits progressive rendering in many browsers, including Internet Explorer. These browsers block rendering to avoid having to redraw elements of the page if their styles change. The user is stuck viewing a blank white page. <o:p></o:p></p> <p>The <a href="http://www.w3.org/TR/html4/struct/links.html#h-12.3">HTML specification</a> clearly states that stylesheets are to be included in the HEAD of the page: "Unlike A, [LINK] may only appear in the HEAD section of a document, although it may appear any number of times." Neither of the alternatives, the blank white screen or flash of unstyled content, are worth the risk. The optimal solution is to follow the HTML specification and load your stylesheets in the document HEAD.<o:p></o:p></p> <p><a href="http://developer.yahoo.com/performance/rules.html#page-nav">top</a> | <a href="http://developer.yahoo.net/blog/archives/2007/07/high_performanc_4.html">discuss this rule</a><o:p></o:p></p> <h3 id="js_bottom">Put Scripts at the Bottom<o:p></o:p></h3> <p class=date>tag: javascript<o:p></o:p></p> <p>The problem caused by scripts is that they block parallel downloads. The <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html#sec8.1.4">HTTP/1.1 specification</a> suggests that browsers download no more than two components in parallel per hostname. If you serve your images from multiple hostnames, you can get more than two downloads to occur in parallel. While a script is downloading, however, the browser won't start any other downloads, even on different hostnames. <o:p></o:p></p> <p>In some situations it's not easy to move scripts to the bottom. If, for example, the script uses <code><span style='font-size:10.0pt'>document.write</span></code> to insert part of the page's content, it can't be moved lower in the page. There might also be scoping issues. In many cases, there are ways to workaround these situations.<o:p></o:p></p> <p>An alternative suggestion that often comes up is to use deferred scripts. The <code><span style='font-size:10.0pt'>DEFER</span></code> attribute indicates that the script does not contain document.write, and is a clue to browsers that they can continue rendering. Unfortunately, Firefox doesn't support the <code><span style='font-size:10.0pt'>DEFER</span></code> attribute. In Internet Explorer, the script may be deferred, but not as much as desired. If a script can be deferred, it can also be moved to the bottom of the page. That will make your web pages load faster.<o:p></o:p></p> <p><a href="http://developer.yahoo.com/performance/rules.html#page-nav">top</a> | <a href="http://developer.yahoo.net/blog/archives/2007/07/high_performanc_5.html">discuss this rule</a><o:p></o:p></p> <h3 id="css_expressions">Avoid CSS Expressions<o:p></o:p></h3> <p class=date>tag: css<o:p></o:p></p> <p>CSS expressions are a powerful (and dangerous) way to set CSS properties dynamically. They were supported in Internet Explorer starting with version 5, but were <a href="http://msdn.microsoft.com/en-us/library/ms537634%28VS.85%29.aspx">deprecated starting with IE8</a>. As an example, the background color could be set to alternate every hour using CSS expressions:<o:p></o:p></p> <pre> background-color: expression( (new Date()).getHours()%2 ? "#B8D4FF" : "#F08A00" );<o:p></o:p></pre> <p class=MsoNormal><o:p> </o:p></p> <p>As shown here, the <code><span style='font-size:10.0pt'>expression</span></code> method accepts a JavaScript expression. The CSS property is set to the result of evaluating the JavaScript expression. The <code><span style='font-size:10.0pt'>expression</span></code> method is ignored by other browsers, so it is useful for setting properties in Internet Explorer needed to create a consistent experience across browsers.<o:p></o:p></p> <p>The problem with expressions is that they are evaluated more frequently than most people expect. Not only are they evaluated when the page is rendered and resized, but also when the page is scrolled and even when the user moves the mouse over the page. Adding a counter to the CSS expression allows us to keep track of when and how often a CSS expression is evaluated. Moving the mouse around the page can easily generate more than 10,000 evaluations.<o:p></o:p></p> <p>One way to reduce the number of times your CSS expression is evaluated is to use one-time expressions, where the first time the expression is evaluated it sets the style property to an explicit value, which replaces the CSS expression. If the style property must be set dynamically throughout the life of the page, using event handlers instead of CSS expressions is an alternative approach. If you must use CSS expressions, remember that they may be evaluated thousands of times and could affect the performance of your page.<o:p></o:p></p> <p><a href="http://developer.yahoo.com/performance/rules.html#page-nav">top</a> | <a href="http://developer.yahoo.net/blog/archives/2007/07/high_performanc_6.html">discuss this rule</a><o:p></o:p></p> <h3 id=external>Make JavaScript and CSS External<o:p></o:p></h3> <p class=date>tag: javascript, css<o:p></o:p></p> <p>Many of these performance rules deal with how external components are managed. However, before these considerations arise you should ask a more basic question: Should JavaScript and CSS be contained in external files, or inlined in the page itself?<o:p></o:p></p> <p>Using external files in the real world generally produces faster pages because the JavaScript and CSS files are cached by the browser. JavaScript and CSS that are inlined in HTML documents get downloaded every time the HTML document is requested. This reduces the number of HTTP requests that are needed, but increases the size of the HTML document. On the other hand, if the JavaScript and CSS are in external files cached by the browser, the size of the HTML document is reduced without increasing the number of HTTP requests. <o:p></o:p></p> <p>The key factor, then, is the frequency with which external JavaScript and CSS components are cached relative to the number of HTML documents requested. This factor, although difficult to quantify, can be gauged using various metrics. If users on your site have multiple page views per session and many of your pages re-use the same scripts and stylesheets, there is a greater potential benefit from cached external files. <o:p></o:p></p> <p>Many web sites fall in the middle of these metrics. For these sites, the best solution generally is to deploy the JavaScript and CSS as external files. The only exception where inlining is preferable is with home pages, such as <a href="http://www.yahoo.com">Yahoo!'s front page</a> and <a href="http://my.yahoo.com">My Yahoo!</a>. Home pages that have few (perhaps only one) page view per session may find that inlining JavaScript and CSS results in faster end-user response times.<o:p></o:p></p> <p>For front pages that are typically the first of many page views, there are techniques that leverage the reduction of HTTP requests that inlining provides, as well as the caching benefits achieved through using external files. One such technique is to inline JavaScript and CSS in the front page, but dynamically download the external files after the page has finished loading. Subsequent pages would reference the external files that should already be in the browser's cache.<o:p></o:p></p> <p><a href="http://developer.yahoo.com/performance/rules.html#page-nav">top</a> | <a href="http://developer.yahoo.net/blog/archives/2007/07/rule_8_make_jav.html">discuss this rule</a><o:p></o:p></p> <h3 id="dns_lookups">Reduce DNS Lookups<o:p></o:p></h3> <p class=date>tag: content<o:p></o:p></p> <p>The Domain Name System (DNS) maps hostnames to IP addresses, just as phonebooks map people's names to their phone numbers. When you type www.yahoo.com into your browser, a DNS resolver contacted by the browser returns that server's IP address. DNS has a cost. It typically takes 20-120 milliseconds for DNS to lookup the IP address for a given hostname. The browser can't download anything from this hostname until the DNS lookup is completed. <o:p></o:p></p> <p>DNS lookups are cached for better performance. This caching can occur on a special caching server, maintained by the user's ISP or local area network, but there is also caching that occurs on the individual user's computer. The DNS information remains in the operating system's DNS cache (the "DNS Client service" on Microsoft Windows). Most browsers have their own caches, separate from the operating system's cache. As long as the browser keeps a DNS record in its own cache, it doesn't bother the operating system with a request for the record.<o:p></o:p></p> <p>Internet Explorer caches DNS lookups for 30 minutes by default, as specified by the <code><span style='font-size:10.0pt'>DnsCacheTimeout</span></code> registry setting. Firefox caches DNS lookups for 1 minute, controlled by the <code><span style='font-size:10.0pt'>network.dnsCacheExpiration</span></code> configuration setting. (Fasterfox changes this to 1 hour.)<o:p></o:p></p> <p>When the client's DNS cache is empty (for both the browser and the operating system), the number of DNS lookups is equal to the number of unique hostnames in the web page. This includes the hostnames used in the page's URL, images, script files, stylesheets, Flash objects, etc. Reducing the number of unique hostnames reduces the number of DNS lookups. <o:p></o:p></p> <p>Reducing the number of unique hostnames has the potential to reduce the amount of parallel downloading that takes place in the page. Avoiding DNS lookups cuts response times, but reducing parallel downloads may increase response times. My guideline is to split these components across at least two but no more than four hostnames. This results in a good compromise between reducing DNS lookups and allowing a high degree of parallel downloads.<o:p></o:p></p> <p><a href="http://developer.yahoo.com/performance/rules.html#page-nav">top</a> | <a href="http://developer.yahoo.net/blog/archives/2007/07/high_performanc_7.html">discuss this rule</a><o:p></o:p></p> <h3 id=minify>Minify JavaScript and CSS<o:p></o:p></h3> <p class=date>tag: javascript, css<o:p></o:p></p> <p>Minification is the practice of removing unnecessary characters from code to reduce its size thereby improving load times. When code is minified all comments are removed, as well as unneeded white space characters (space, newline, and tab). In the case of JavaScript, this improves response time performance because the size of the downloaded file is reduced. Two popular tools for minifying JavaScript code are <a href="http://crockford.com/javascript/jsmin">JSMin</a> and <a href="http://developer.yahoo.com/yui/compressor/">YUI Compressor</a>. The YUI compressor can also minify CSS.<o:p></o:p></p> <p>Obfuscation is an alternative optimization that can be applied to source code. It's more complex than minification and thus more likely to generate bugs as a result of the obfuscation step itself. In a survey of ten top U.S. web sites, minification achieved a 21% size reduction versus 25% for obfuscation. Although obfuscation has a higher size reduction, minifying JavaScript is less risky.<o:p></o:p></p> <p>In addition to minifying external scripts and styles, inlined <code><span style='font-size:10.0pt'><script></span></code> and <code><span style='font-size:10.0pt'><style></span></code> blocks can and should also be minified. Even if you gzip your scripts and styles, minifying them will still reduce the size by 5% or more. As the use and size of JavaScript and CSS increases, so will the savings gained by minifying your code.<o:p></o:p></p> <p><a href="http://developer.yahoo.com/performance/rules.html#page-nav">top</a> | <a href="http://developer.yahoo.net/blog/archives/2007/07/high_performanc_8.html">discuss this rule</a><o:p></o:p></p> <h3 id=redirects>Avoid Redirects<o:p></o:p></h3> <p class=date>tag: content<o:p></o:p></p> <p>Redirects are accomplished using the 301 and 302 status codes. Here's an example of the HTTP headers in a 301 response:<o:p></o:p></p> <pre> HTTP/1.1 301 Moved Permanently<o:p></o:p></pre><pre> Location: http://example.com/newuri<o:p></o:p></pre><pre> Content-Type: text/html<o:p></o:p></pre> <p class=MsoNormal><o:p> </o:p></p> <p>The browser automatically takes the user to the URL specified in the <code><span style='font-size:10.0pt'>Location</span></code> field. All the information necessary for a redirect is in the headers. The body of the response is typically empty. Despite their names, neither a 301 nor a 302 response is cached in practice unless additional headers, such as <code><span style='font-size:10.0pt'>Expires</span></code> or <code><span style='font-size:10.0pt'>Cache-Control</span></code>, indicate it should be. The meta refresh tag and JavaScript are other ways to direct users to a different URL, but if you must do a redirect, the preferred technique is to use the standard 3xx HTTP status codes, primarily to ensure the back button works correctly.<o:p></o:p></p> <p>The main thing to remember is that redirects slow down the user experience. Inserting a redirect between the user and the HTML document delays everything in the page since nothing in the page can be rendered and no components can start being downloaded until the HTML document has arrived.<o:p></o:p></p> <p>One of the most wasteful redirects happens frequently and web developers are generally not aware of it. It occurs when a trailing slash (/) is missing from a URL that should otherwise have one. For example, going to <a href="http://astrology.yahoo.com/astrology">http://astrology.yahoo.com/astrology</a> results in a 301 response containing a redirect to <a href="http://astrology.yahoo.com/astrology/">http://astrology.yahoo.com/astrology/</a> (notice the added trailing slash). This is fixed in Apache by using <code><span style='font-size:10.0pt'>Alias</span></code> or <code><span style='font-size: 10.0pt'>mod_rewrite</span></code>, or the <code><span style='font-size:10.0pt'>DirectorySlash</span></code> directive if you're using Apache handlers.<o:p></o:p></p> <p>Connecting an old web site to a new one is another common use for redirects. Others include connecting different parts of a website and directing the user based on certain conditions (type of browser, type of user account, etc.). Using a redirect to connect two web sites is simple and requires little additional coding. Although using redirects in these situations reduces the complexity for developers, it degrades the user experience. Alternatives for this use of redirects include using <code><span style='font-size:10.0pt'>Alias</span></code> and <code><span style='font-size:10.0pt'>mod_rewrite</span></code> if the two code paths are hosted on the same server. If a domain name change is the cause of using redirects, an alternative is to create a CNAME (a DNS record that creates an alias pointing from one domain name to another) in combination with <code><span style='font-size:10.0pt'>Alias</span></code> or <code><span style='font-size: 10.0pt'>mod_rewrite</span></code>.<o:p></o:p></p> <p><a href="http://developer.yahoo.com/performance/rules.html#page-nav">top</a> | <a href="http://developer.yahoo.net/blog/archives/2007/07/high_performanc_9.html">discuss this rule</a><o:p></o:p></p> <h3 id="js_dupes">Remove Duplicate Scripts<o:p></o:p></h3> <p class=date>tag: javascript<o:p></o:p></p> <p>It hurts performance to include the same JavaScript file twice in one page. This isn't as unusual as you might think. A review of the ten top U.S. web sites shows that two of them contain a duplicated script. Two main factors increase the odds of a script being duplicated in a single web page: team size and number of scripts. When it does happen, duplicate scripts hurt performance by creating unnecessary HTTP requests and wasted JavaScript execution.<o:p></o:p></p> <p>Unnecessary HTTP requests happen in Internet Explorer, but not in Firefox. In Internet Explorer, if an external script is included twice and is not cacheable, it generates two HTTP requests during page loading. Even if the script is cacheable, extra HTTP requests occur when the user reloads the page.<o:p></o:p></p> <p>In addition to generating wasteful HTTP requests, time is wasted evaluating the script multiple times. This redundant JavaScript execution happens in both Firefox and Internet Explorer, regardless of whether the script is cacheable.<o:p></o:p></p> <p>One way to avoid accidentally including the same script twice is to implement a script management module in your templating system. The typical way to include a script is to use the SCRIPT tag in your HTML page.<o:p></o:p></p> <pre> <script type="text/javascript" src="menu_1.0.17.js"></script><o:p></o:p></pre> <p class=MsoNormal><o:p> </o:p></p> <p>An alternative in PHP would be to create a function called <code><span style='font-size:10.0pt'>insertScript</span></code>.<o:p></o:p></p> <pre> <?php insertScript("menu.js") ?><o:p></o:p></pre> <p class=MsoNormal><o:p> </o:p></p> <p>In addition to preventing the same script from being inserted multiple times, this function could handle other issues with scripts, such as dependency checking and adding version numbers to script filenames to support far future Expires headers.<o:p></o:p></p> <p><a href="http://developer.yahoo.com/performance/rules.html#page-nav">top</a> | <a href="http://developer.yahoo.net/blog/archives/2007/07/high_performanc_10.html">discuss this rule</a><o:p></o:p></p> <h3 id=etags>Configure ETags<o:p></o:p></h3> <p class=date>tag: server<o:p></o:p></p> <p>Entity tags (ETags) are a mechanism that web servers and browsers use to determine whether the component in the browser's cache matches the one on the origin server. (An "entity" is another word a "component": images, scripts, stylesheets, etc.) ETags were added to provide a mechanism for validating entities that is more flexible than the last-modified date. An ETag is a string that uniquely identifies a specific version of a component. The only format constraints are that the string be quoted. The origin server specifies the component's ETag using the <code><span style='font-size:10.0pt'>ETag</span></code> response header.<o:p></o:p></p> <pre> HTTP/1.1 200 OK<o:p></o:p></pre><pre> Last-Modified: Tue, 12 Dec 2006 03:03:59 GMT<o:p></o:p></pre><pre> ETag: "10c24bc-4ab-457e1c1f"<o:p></o:p></pre><pre> Content-Length: 12195<o:p></o:p></pre> <p class=MsoNormal><o:p> </o:p></p> <p>Later, if the browser has to validate a component, it uses the <code><span style='font-size:10.0pt'>If-None-Match</span></code> header to pass the ETag back to the origin server. If the ETags match, a 304 status code is returned reducing the response by 12195 bytes for this example. <o:p></o:p></p> <pre> GET /i/yahoo.gif HTTP/1.1<o:p></o:p></pre><pre> Host: us.yimg.com<o:p></o:p></pre><pre> If-Modified-Since: Tue, 12 Dec 2006 03:03:59 GMT<o:p></o:p></pre><pre> If-None-Match: "10c24bc-4ab-457e1c1f"<o:p></o:p></pre><pre> HTTP/1.1 304 Not Modified<o:p></o:p></pre> <p class=MsoNormal><o:p> </o:p></p> <p>The problem with ETags is that they typically are constructed using attributes that make them unique to a specific server hosting a site. ETags won't match when a browser gets the original component from one server and later tries to validate that component on a different server, a situation that is all too common on Web sites that use a cluster of servers to handle requests. By default, both Apache and IIS embed data in the ETag that dramatically reduces the odds of the validity test succeeding on web sites with multiple servers. <o:p></o:p></p> <p>The ETag format for Apache 1.3 and 2.x is <code><span style='font-size:10.0pt'>inode-size-timestamp</span></code>. Although a given file may reside in the same directory across multiple servers, and have the same file size, permissions, timestamp, etc., its inode is different from one server to the next. <o:p></o:p></p> <p>IIS 5.0 and 6.0 have a similar issue with ETags. The format for ETags on IIS is <code><span style='font-size:10.0pt'>Filetimestamp:ChangeNumber</span></code>. A <code><span style='font-size:10.0pt'>ChangeNumber</span></code> is a counter used to track configuration changes to IIS. It's unlikely that the <code><span style='font-size:10.0pt'>ChangeNumber</span></code> is the same across all IIS servers behind a web site. <o:p></o:p></p> <p>The end result is ETags generated by Apache and IIS for the exact same component won't match from one server to another. If the ETags don't match, the user doesn't receive the small, fast 304 response that ETags were designed for; instead, they'll get a normal 200 response along with all the data for the component. If you host your web site on just one server, this isn't a problem. But if you have multiple servers hosting your web site, and you're using Apache or IIS with the default ETag configuration, your users are getting slower pages, your servers have a higher load, you're consuming greater bandwidth, and proxies aren't caching your content efficiently. Even if your components have a far future <code><span style='font-size:10.0pt'>Expires</span></code> header, a conditional GET request is still made whenever the user hits Reload or Refresh. <o:p></o:p></p> <p>If you're not taking advantage of the flexible validation model that ETags provide, it's better to just remove the ETag altogether. The <code><span style='font-size:10.0pt'>Last-Modified</span></code> header validates based on the component's timestamp. And removing the ETag reduces the size of the HTTP headers in both the response and subsequent requests. This <a href="http://support.microsoft.com/?id=922733">Microsoft Support article</a> describes how to remove ETags. In Apache, this is done by simply adding the following line to your Apache configuration file: <o:p></o:p></p> <pre> FileETag none<o:p></o:p></pre> <p class=MsoNormal><o:p> </o:p></p> <p><a href="http://developer.yahoo.com/performance/rules.html#page-nav">top</a> | <a href="http://developer.yahoo.net/blog/archives/2007/07/high_performanc_11.html">discuss this rule</a><o:p></o:p></p> <h3 id=cacheajax>Make Ajax Cacheable<o:p></o:p></h3> <p class=date>tag: content<o:p></o:p></p> <p>One of the cited benefits of Ajax is that it provides instantaneous feedback to the user because it requests information asynchronously from the backend web server. However, using Ajax is no guarantee that the user won't be twiddling his thumbs waiting for those asynchronous JavaScript and XML responses to return. In many applications, whether or not the user is kept waiting depends on how Ajax is used. For example, in a web-based email client the user will be kept waiting for the results of an Ajax request to find all the email messages that match their search criteria. It's important to remember that "asynchronous" does not imply "instantaneous".<o:p></o:p></p> <p>To improve performance, it's important to optimize these Ajax responses. The most important way to improve the performance of Ajax is to make the responses cacheable, as discussed in <a href="http://developer.yahoo.com/performance/rules.html#expires">Add an Expires or a Cache-Control Header</a>. Some of the other rules also apply to Ajax:<o:p></o:p></p> <ul type=disc> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l13 level1 lfo10'><a href="http://developer.yahoo.com/performance/rules.html#gzip">Gzip Components</a><o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l13 level1 lfo10'><a href="http://developer.yahoo.com/performance/rules.html#dns_lookups">Reduce DNS Lookups</a><o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l13 level1 lfo10'><a href="http://developer.yahoo.com/performance/rules.html#minify">Minify JavaScript</a><o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l13 level1 lfo10'><a href="http://developer.yahoo.com/performance/rules.html#redirects">Avoid Redirects</a><o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l13 level1 lfo10'><a href="http://developer.yahoo.com/performance/rules.html#etags">Configure ETags</a><o:p></o:p></li> </ul> <p class=MsoNormal><o:p> </o:p></p> <p>Let's look at an example. A Web 2.0 email client might use Ajax to download the user's address book for autocompletion. If the user hasn't modified her address book since the last time she used the email web app, the previous address book response could be read from cache if that Ajax response was made cacheable with a future Expires or Cache-Control header. The browser must be informed when to use a previously cached address book response versus requesting a new one. This could be done by adding a timestamp to the address book Ajax URL indicating the last time the user modified her address book, for example, <code><span style='font-size:10.0pt'>&t=1190241612</span></code>. If the address book hasn't been modified since the last download, the timestamp will be the same and the address book will be read from the browser's cache eliminating an extra HTTP roundtrip. If the user has modified her address book, the timestamp ensures the new URL doesn't match the cached response, and the browser will request the updated address book entries.<o:p></o:p></p> <p>Even though your Ajax responses are created dynamically, and might only be applicable to a single user, they can still be cached. Doing so will make your Web 2.0 apps faster.<o:p></o:p></p> <p><a href="http://developer.yahoo.com/performance/rules.html#page-nav">top</a> | <a href="http://developer.yahoo.net/blog/archives/2007/09/high_performanc_12.html">discuss this rule</a><o:p></o:p></p> <h3 id=flush>Flush the Buffer Early<o:p></o:p></h3> <p class=date>tag: server<o:p></o:p></p> <p>When users request a page, it can take anywhere from 200 to 500ms for the backend server to stitch together the HTML page. During this time, the browser is idle as it waits for the data to arrive. In PHP you have the function <a href="http://php.net/flush">flush()</a>. It allows you to send your partially ready HTML response to the browser so that the browser can start fetching components while your backend is busy with the rest of the HTML page. The benefit is mainly seen on busy backends or light frontends. <o:p></o:p></p> <p>A good place to consider flushing is right after the HEAD because the HTML for the head is usually easier to produce and it allows you to include any CSS and JavaScript files for the browser to start fetching in parallel while the backend is still processing. <o:p></o:p></p> <p>Example:<o:p></o:p></p> <pre> ... <!-- css, js --><o:p></o:p></pre><pre> </head><o:p></o:p></pre><pre> <span class=hilite><?php flush(); ?></span><o:p></o:p></pre><pre> <body><o:p></o:p></pre><pre> ... <!-- content --><o:p></o:p></pre> <p class=MsoNormal><o:p> </o:p></p> <p><a href="http://search.yahoo.com">Yahoo! search</a> pioneered research and real user testing to prove the benefits of using this technique.<o:p></o:p></p> <p><a href="http://developer.yahoo.com/performance/rules.html#page-nav">top</a><o:p></o:p></p> <h3 id="ajax_get">Use GET for AJAX Requests<o:p></o:p></h3> <p class=date>tag: server<o:p></o:p></p> <p>The <a href="http://mail.yahoo.com">Yahoo! Mail</a> team found that when using <code><span style='font-size:10.0pt'>XMLHttpRequest</span></code>, POST is implemented in the browsers as a two-step process: sending the headers first, then sending data. So it's best to use GET, which only takes one TCP packet to send (unless you have a lot of cookies). The maximum URL length in IE is 2K, so if you send more than 2K data you might not be able to use GET. <o:p></o:p></p> <p>An interesting side affect is that POST without actually posting any data behaves like GET. Based on the <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html">HTTP specs</a>, GET is meant for retrieving information, so it makes sense (semantically) to use GET when you're only requesting data, as opposed to sending data to be stored server-side. <o:p></o:p></p> <p><a href="http://developer.yahoo.com/performance/rules.html#page-nav">top</a><o:p></o:p></p> <h3 id=postload>Post-load Components<o:p></o:p></h3> <p class=date>tag: content<o:p></o:p></p> <p>You can take a closer look at your page and ask yourself: "What's absolutely required in order to render the page initially?". The rest of the content and components can wait. <o:p></o:p></p> <p>JavaScript is an ideal candidate for splitting before and after the onload event. For example if you have JavaScript code and libraries that do drag and drop and animations, those can wait, because dragging elements on the page comes after the initial rendering. Other places to look for candidates for post-loading include hidden content (content that appears after a user action) and images below the fold. <o:p></o:p></p> <p>Tools to help you out in your effort: <a href="http://developer.yahoo.com/yui/imageloader/">YUI Image Loader</a> allows you to delay images below the fold and the <a href="http://developer.yahoo.com/yui/get/">YUI Get utility</a> is an easy way to include JS and CSS on the fly. For an example in the wild take a look at <a href="http://www.yahoo.com">Yahoo! Home Page</a> with Firebug's Net Panel turned on. <o:p></o:p></p> <p>It's good when the performance goals are inline with other web development best practices. In this case, the idea of progressive enhancement tells us that JavaScript, when supported, can improve the user experience but you have to make sure the page works even without JavaScript. So after you've made sure the page works fine, you can enhance it with some post-loaded scripts that give you more bells and whistles such as drag and drop and animations. <o:p></o:p></p> <p><a href="http://developer.yahoo.com/performance/rules.html#page-nav">top</a><o:p></o:p></p> <h3 id=preload>Preload Components<o:p></o:p></h3> <p class=date>tag: content<o:p></o:p></p> <p>Preload may look like the opposite of post-load, but it actually has a different goal. By preloading components you can take advantage of the time the browser is idle and request components (like images, styles and scripts) you'll need in the future. This way when the user visits the next page, you could have most of the components already in the cache and your page will load much faster for the user. <o:p></o:p></p> <p>There are actually several types of preloading: <o:p></o:p></p> <ul type=disc> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l4 level1 lfo11'><em><span style='font-family:"Calibri","sans-serif"'>Unconditional</span></em> preload - as soon as onload fires, you go ahead and fetch some extra components. Check google.com for an example of how a sprite image is requested onload. This sprite image is not needed on the google.com homepage, but it is needed on the consecutive search result page.<o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l4 level1 lfo11'><em><span style='font-family:"Calibri","sans-serif"'>Conditional</span></em> preload - based on a user action you make an educated guess where the user is headed next and preload accordingly. On <a href="http://search.yahoo.com">search.yahoo.com</a> you can see how some extra components are requested after you start typing in the input box.<o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l4 level1 lfo11'><em><span style='font-family:"Calibri","sans-serif"'>Anticipated</span></em> preload - preload in advance before launching a redesign. It often happens after a redesign that you hear: "The new site is cool, but it's slower than before". Part of the problem could be that the users were visiting your old site with a full cache, but the new one is always an empty cache experience. You can mitigate this side effect by preloading some components before you even launched the redesign. Your old site can use the time the browser is idle and request images and scripts that will be used by the new site<o:p></o:p></li> </ul> <p><a href="http://developer.yahoo.com/performance/rules.html#page-nav">top</a><o:p></o:p></p> <h3 id="min_dom">Reduce the Number of DOM Elements<o:p></o:p></h3> <p class=date>tag: content<o:p></o:p></p> <p>A complex page means more bytes to download and it also means slower DOM access in JavaScript. It makes a difference if you loop through 500 or 5000 DOM elements on the page when you want to add an event handler for example. <o:p></o:p></p> <p>A high number of DOM elements can be a symptom that there's something that should be improved with the markup of the page without necessarily removing content. Are you using nested tables for layout purposes? Are you throwing in more <code><span style='font-size:10.0pt'><div></span></code>s only to fix layout issues? Maybe there's a better and more semantically correct way to do your markup. <o:p></o:p></p> <p>A great help with layouts are the <a href="http://developer.yahoo.com/yui/">YUI CSS utilities</a>: grids.css can help you with the overall layout, fonts.css and reset.css can help you strip away the browser's defaults formatting. This is a chance to start fresh and think about your markup, for example use <code><span style='font-size:10.0pt'><div></span></code>s only when it makes sense semantically, and not because it renders a new line. <o:p></o:p></p> <p>The number of DOM elements is easy to test, just type in Firebug's console:<br> <code><span style='font-size:10.0pt'>document.getElementsByTagName('*').length</span></code> <o:p></o:p></p> <p>And how many DOM elements are too many? Check other similar pages that have good markup. For example the <a href="http://www.yahoo.com">Yahoo! Home Page</a> is a pretty busy page and still under 700 elements (HTML tags). <o:p></o:p></p> <p><a href="http://developer.yahoo.com/performance/rules.html#page-nav">top</a><o:p></o:p></p> <h3 id=split>Split Components Across Domains<o:p></o:p></h3> <p class=date>tag: content<o:p></o:p></p> <p>Splitting components allows you to maximize parallel downloads. Make sure you're using not more than 2-4 domains because of the DNS lookup penalty. For example, you can host your HTML and dynamic content on <code><span style='font-size:10.0pt'>www.example.org</span></code> and split static components between <code><span style='font-size:10.0pt'>static1.example.org</span></code> and <code><span style='font-size:10.0pt'>static2.example.org</span></code> <o:p></o:p></p> <p>For more information check "<a href="http://yuiblog.com/blog/2007/04/11/performance-research-part-4/">Maximizing Parallel Downloads in the Carpool Lane</a>" by Tenni Theurer and Patty Chi. <o:p></o:p></p> <p><a href="http://developer.yahoo.com/performance/rules.html#page-nav">top</a><o:p></o:p></p> <h3 id=iframes>Minimize the Number of iframes<o:p></o:p></h3> <p class=date>tag: content<o:p></o:p></p> <p>Iframes allow an HTML document to be inserted in the parent document. It's important to understand how iframes work so they can be used effectively. <o:p></o:p></p> <p><code><span style='font-size:10.0pt'><iframe></span></code> pros: <o:p></o:p></p> <ul type=disc> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l14 level1 lfo12'>Helps with slow third-party content like badges and ads<o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l14 level1 lfo12'>Security sandbox<o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l14 level1 lfo12'>Download scripts in parallel<o:p></o:p></li> </ul> <p><code><span style='font-size:10.0pt'><iframe></span></code> cons: <o:p></o:p></p> <ul type=disc> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l2 level1 lfo13'>Costly even if blank<o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l2 level1 lfo13'>Blocks page onload<o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l2 level1 lfo13'>Non-semantic<o:p></o:p></li> </ul> <p><a href="http://developer.yahoo.com/performance/rules.html#page-nav">top</a><o:p></o:p></p> <h3 id=no404>No 404s<o:p></o:p></h3> <p class=date>tag: content<o:p></o:p></p> <p>HTTP requests are expensive so making an HTTP request and getting a useless response (i.e. 404 Not Found) is totally unnecessary and will slow down the user experience without any benefit. <o:p></o:p></p> <p>Some sites have helpful 404s "Did you mean X?", which is great for the user experience but also wastes server resources (like database, etc). Particularly bad is when the link to an external JavaScript is wrong and the result is a 404. First, this download will block parallel downloads. Next the browser may try to parse the 404 response body as if it were JavaScript code, trying to find something usable in it. <o:p></o:p></p> <p><a href="http://developer.yahoo.com/performance/rules.html#page-nav">top</a><o:p></o:p></p> <h3 id="cookie_size">Reduce Cookie Size<o:p></o:p></h3> <p class=date>tag: cookie<o:p></o:p></p> <p>HTTP cookies are used for a variety of reasons such as authentication and personalization. Information about cookies is exchanged in the HTTP headers between web servers and browsers. It's important to keep the size of cookies as low as possible to minimize the impact on the user's response time. <o:p></o:p></p> <p>For more information check <a href="http://yuiblog.com/blog/2007/03/01/performance-research-part-3/">"When the Cookie Crumbles"</a> by Tenni Theurer and Patty Chi. The take-home of this research: <o:p></o:p></p> <ul type=disc> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l19 level1 lfo14'>Eliminate unnecessary cookies<o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l19 level1 lfo14'>Keep cookie sizes as low as possible to minimize the impact on the user response time<o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l19 level1 lfo14'>Be mindful of setting cookies at the appropriate domain level so other sub-domains are not affected<o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l19 level1 lfo14'>Set an Expires date appropriately. An earlier Expires date or none removes the cookie sooner, improving the user response time<o:p></o:p></li> </ul> <p><a href="http://developer.yahoo.com/performance/rules.html#page-nav">top</a><o:p></o:p></p> <h3 id="cookie_free">Use Cookie-free Domains for Components<o:p></o:p></h3> <p class=date>tag: cookie<o:p></o:p></p> <p>When the browser makes a request for a static image and sends cookies together with the request, the server doesn't have any use for those cookies. So they only create network traffic for no good reason. You should make sure static components are requested with cookie-free requests. Create a subdomain and host all your static components there. <o:p></o:p></p> <p>If your domain is <code><span style='font-size:10.0pt'>www.example.org</span></code>, you can host your static components on <code><span style='font-size:10.0pt'>static.example.org</span></code>. However, if you've already set cookies on the top-level domain <code><span style='font-size:10.0pt'>example.org</span></code> as opposed to <code><span style='font-size:10.0pt'>www.example.org</span></code>, then all the requests to <code><span style='font-size:10.0pt'>static.example.org</span></code> will include those cookies. In this case, you can buy a whole new domain, host your static components there, and keep this domain cookie-free. Yahoo! uses <code><span style='font-size:10.0pt'>yimg.com</span></code>, YouTube uses <code><span style='font-size:10.0pt'>ytimg.com</span></code>, Amazon uses <code><span style='font-size:10.0pt'>images-amazon.com</span></code> and so on. <o:p></o:p></p> <p>Another benefit of hosting static components on a cookie-free domain is that some proxies might refuse to cache the components that are requested with cookies. On a related note, if you wonder if you should use example.org or www.example.org for your home page, consider the cookie impact. Omitting www leaves you no choice but to write cookies to <code><span style='font-size:10.0pt'>*.example.org</span></code>, so for performance reasons it's best to use the www subdomain and write the cookies to that subdomain. <o:p></o:p></p> <p><a href="http://developer.yahoo.com/performance/rules.html#page-nav">top</a><o:p></o:p></p> <h3 id="dom_access">Minimize DOM Access<o:p></o:p></h3> <p class=date>tag: javascript<o:p></o:p></p> <p>Accessing DOM elements with JavaScript is slow so in order to have a more responsive page, you should: <o:p></o:p></p> <ul type=disc> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l8 level1 lfo15'>Cache references to accessed elements<o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l8 level1 lfo15'>Update nodes "offline" and then add them to the tree<o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l8 level1 lfo15'>Avoid fixing layout with JavaScript<o:p></o:p></li> </ul> <p>For more information check the YUI theatre's <a href="http://yuiblog.com/blog/2007/12/20/video-lecomte/">"High Performance Ajax Applications"</a> by Julien Lecomte. <o:p></o:p></p> <p><a href="http://developer.yahoo.com/performance/rules.html#page-nav">top</a><o:p></o:p></p> <h3 id=events>Develop Smart Event Handlers<o:p></o:p></h3> <p class=date>tag: javascript<o:p></o:p></p> <p>Sometimes pages feel less responsive because of too many event handlers attached to different elements of the DOM tree which are then executed too often. That's why using <em>event delegation</em> is a good approach. If you have 10 buttons inside a <code><span style='font-size:10.0pt'>div</span></code>, attach only one event handler to the div wrapper, instead of one handler for each button. Events bubble up so you'll be able to catch the event and figure out which button it originated from. <o:p></o:p></p> <p>You also don't need to wait for the onload event in order to start doing something with the DOM tree. Often all you need is the element you want to access to be available in the tree. You don't have to wait for all images to be downloaded. <code><span style='font-size:10.0pt'>DOMContentLoaded</span></code> is the event you might consider using instead of onload, but until it's available in all browsers, you can use the <a href="http://developer.yahoo.com/yui/event/">YUI Event</a> utility, which has an <code><span style='font-size:10.0pt'><a href="http://developer.yahoo.com/yui/event/#onavailable">onAvailable</a></span></code> method. <o:p></o:p></p> <p>For more information check the YUI theatre's <a href="http://yuiblog.com/blog/2007/12/20/video-lecomte/">"High Performance Ajax Applications"</a> by Julien Lecomte. <o:p></o:p></p> <p><a href="http://developer.yahoo.com/performance/rules.html#page-nav">top</a><o:p></o:p></p> <h3 id=csslink>Choose <link> over @import<o:p></o:p></h3> <p class=date>tag: css<o:p></o:p></p> <p>One of the previous best practices states that CSS should be at the top in order to allow for progressive rendering. <o:p></o:p></p> <p>In IE <code><span style='font-size:10.0pt'>@import</span></code> behaves the same as using <code><span style='font-size:10.0pt'><link></span></code> at the bottom of the page, so it's best not to use it. <o:p></o:p></p> <p><a href="http://developer.yahoo.com/performance/rules.html#page-nav">top</a><o:p></o:p></p> <h3 id="no_filters">Avoid Filters<o:p></o:p></h3> <p class=date>tag: css<o:p></o:p></p> <p>The IE-proprietary <code><span style='font-size:10.0pt'>AlphaImageLoader</span></code> filter aims to fix a problem with semi-transparent true color PNGs in IE versions < 7. The problem with this filter is that it blocks rendering and freezes the browser while the image is being downloaded. It also increases memory consumption and is applied per element, not per image, so the problem is multiplied. <o:p></o:p></p> <p>The best approach is to avoid <code><span style='font-size:10.0pt'>AlphaImageLoader</span></code> completely and use gracefully degrading PNG8 instead, which are fine in IE. If you absolutely need <code><span style='font-size:10.0pt'>AlphaImageLoader</span></code>, use the underscore hack <code><span style='font-size:10.0pt'>_filter</span></code> as to not penalize your IE7+ users. <o:p></o:p></p> <p><a href="http://developer.yahoo.com/performance/rules.html#page-nav">top</a><o:p></o:p></p> <h3 id="opt_images">Optimize Images<o:p></o:p></h3> <p class=date>tag: images<o:p></o:p></p> <p>After a designer is done with creating the images for your web page, there are still some things you can try before you FTP those images to your web server. <o:p></o:p></p> <ul type=disc> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l9 level1 lfo16'>You can check the GIFs and see if they are using a palette size corresponding to the number of colors in the image. Using <a href="http://www.imagemagick.org">imagemagick</a> it's easy to check using <br> <code><span style='font-size:10.0pt'>identify -verbose image.gif</span></code> <br> When you see an image useing 4 colors and a 256 color "slots" in the palette, there is room for improvement. <o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l9 level1 lfo16'>Try converting GIFs to PNGs and see if there is a saving. More often than not, there is. Developers often hesitate to use PNGs due to the limited support in browsers, but this is now a thing of the past. The only real problem is alpha-transparency in true color PNGs, but then again, GIFs are not true color and don't support variable transparency either. So anything a GIF can do, a palette PNG (PNG8) can do too (except for animations). This simple imagemagick command results in totally safe-to-use PNGs:<br> <code><span style='font-size:10.0pt'>convert image.gif image.png</span></code> <br> "All we are saying is: Give PiNG a Chance!" <o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l9 level1 lfo16'>Run <a href="http://pmt.sourceforge.net/pngcrush/">pngcrush</a> (or any other PNG optimizer tool) on all your PNGs. Example: <br> <code><span style='font-size:10.0pt'>pngcrush image.png -rem alla -reduce -brute result.png</span></code> <o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l9 level1 lfo16'>Run jpegtran on all your JPEGs. This tool does lossless JPEG operations such as rotation and can also be used to optimize and remove comments and other useless information (such as EXIF information) from your images. <br> <code><span style='font-size:10.0pt'>jpegtran -copy none -optimize -perfect src.jpg dest.jpg</span></code> <o:p></o:p></li> </ul> <p><a href="http://developer.yahoo.com/performance/rules.html#page-nav">top</a><o:p></o:p></p> <h3 id="opt_sprites">Optimize CSS Sprites<o:p></o:p></h3> <p class=date>tag: images<o:p></o:p></p> <ul type=disc> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l16 level1 lfo17'>Arranging the images in the sprite horizontally as opposed to vertically usually results in a smaller file size.<o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l16 level1 lfo17'>Combining similar colors in a sprite helps you keep the color count low, ideally under 256 colors so to fit in a PNG8.<o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l16 level1 lfo17'>"Be mobile-friendly" and don't leave big gaps between the images in a sprite. This doesn't affect the file size as much but requires less memory for the user agent to decompress the image into a pixel map. 100x100 image is 10 thousand pixels, where 1000x1000 is 1 million pixels <o:p></o:p></li> </ul> <p><a href="http://developer.yahoo.com/performance/rules.html#page-nav">top</a><o:p></o:p></p> <h3 id="no_scale">Don't Scale Images in HTML<o:p></o:p></h3> <p class=date>tag: images<o:p></o:p></p> <p>Don't use a bigger image than you need just because you can set the width and height in HTML. If you need <br> <code><span style='font-size:10.0pt'><img width="100" height="100" src="mycat.jpg" alt="My Cat" /></span></code> <br> then your image (mycat.jpg) should be 100x100px rather than a scaled down 500x500px image. <o:p></o:p></p> <p><a href="http://developer.yahoo.com/performance/rules.html#page-nav">top</a><o:p></o:p></p> <h3 id=favicon>Make favicon.ico Small and Cacheable<o:p></o:p></h3> <p class=date>tag: images<o:p></o:p></p> <p>The favicon.ico is an image that stays in the root of your server. It's a necessary evil because even if you don't care about it the browser will still request it, so it's better not to respond with a <code><span style='font-size: 10.0pt'>404 Not Found</span></code>. Also since it's on the same server, cookies are sent every time it's requested. This image also interferes with the download sequence, for example in IE when you request extra components in the onload, the favicon will be downloaded before these extra components. <o:p></o:p></p> <p>So to mitigate the drawbacks of having a favicon.ico make sure: <o:p></o:p></p> <ul type=disc> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l11 level1 lfo18'>It's small, preferably under 1K.<o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l11 level1 lfo18'>Set Expires header with what you feel comfortable (since you cannot rename it if you decide to change it). You can probably safely set the Expires header a few months in the future. You can check the last modified date of your current favicon.ico to make an informed decision. <o:p></o:p></li> </ul> <p><a href="http://www.imagemagick.org">Imagemagick</a> can help you create small favicons <o:p></o:p></p> <p><a href="http://developer.yahoo.com/performance/rules.html#page-nav">top</a><o:p></o:p></p> <h3 id=under25>Keep Components under 25K<o:p></o:p></h3> <p class=date>tag: mobile<o:p></o:p></p> <p>This restriction is related to the fact that iPhone won't cache components bigger than 25K. Note that this is the <em>uncompressed</em> size. This is where minification is important because gzip alone may not be sufficient. <o:p></o:p></p> <p>For more information check "<a href="http://yuiblog.com/blog/2008/02/06/iphone-cacheability/">Performance Research, Part 5: iPhone Cacheability - Making it Stick</a>" by Wayne Shea and Tenni Theurer. <o:p></o:p></p> <p><a href="http://developer.yahoo.com/performance/rules.html#page-nav">top</a><o:p></o:p></p> <h3 id=multipart>Pack Components into a Multipart Document<o:p></o:p></h3> <p class=date>tag: mobile<o:p></o:p></p> <p>Packing components into a multipart document is like an email with attachments, it helps you fetch several components with one HTTP request (remember: HTTP requests are expensive). When you use this technique, first check if the user agent supports it (iPhone does not). <o:p></o:p></p> <h3 id=emptysrc>Avoid Empty Image src<o:p></o:p></h3> <p class=date>tag: server<o:p></o:p></p> <p>Image with empty string <b>src</b> attribute occurs more than one will expect. It appears in two form: <o:p></o:p></p> <ol start=1 type=1> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l6 level1 lfo19'>straight HTML<o:p></o:p></li> </ol> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; margin-left:.5in'><img src=""><o:p></o:p></p> <ol start=2 type=1> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l6 level1 lfo19'>JavaScript<o:p></o:p></li> </ol> <p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; margin-left:.5in'>var img = new Image();<br> img.src = "";<o:p></o:p></p> <p>Both forms cause the same effect: browser makes another request to your server. <o:p></o:p></p> <ul type=disc> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l1 level1 lfo20'><b>Internet Explorer</b> makes a request to the directory in which the page is located.<o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l1 level1 lfo20'><b>Safari and Chrome</b> make a request to the actual page itself.<o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l1 level1 lfo20'><b>Firefox</b> 3 and earlier versions behave the same as Safari and Chrome, but version 3.5 addressed this issue<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=444931">[bug 444931]</a> and no longer sends a request.<o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l1 level1 lfo20'><b>Opera</b> does not do anything when an empty image src is encountered.<o:p></o:p></li> </ul> <p class=MsoNormal><o:p> </o:p></p> <p><b>Why is this behavior bad? </b><o:p></o:p></p> <ol start=1 type=1> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l20 level1 lfo21'>Cripple your servers by sending a large amount of unexpected traffic, especially for pages that get millions of page views per day.<o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l20 level1 lfo21'>Waste server computing cycles generating a page that will never be viewed.<o:p></o:p></li> <li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto; mso-list:l20 level1 lfo21'>Possibly corrupt user data. If you are tracking state in the request, either by cookies or in another way, you have the possibility of destroying data. Even though the image request does not return an image, all of the headers are read and accepted by the browser, including all cookies. While the rest of the response is thrown away, the damage may already be done.<o:p></o:p></li> </ol> <p class=MsoNormal><o:p> </o:p></p> <p>The root cause of this behavior is the way that URI resolution is performed in browsers. This behavior is defined in RFC 3986 - Uniform Resource Identifiers. When an empty string is encountered as a URI, it is considered a relative URI and is resolved according to the algorithm defined in section 5.2. This specific example, an empty string, is listed in section 5.4. Firefox, Safari, and Chrome are all resolving an empty string correctly per the specification, while Internet Explorer is resolving it incorrectly, apparently in line with an earlier version of the specification, RFC 2396 - Uniform Resource Identifiers (this was obsoleted by RFC 3986). So technically, the browsers are doing what they are supposed to do to resolve relative URIs. The problem is that in this context, the empty string is clearly unintentional. <o:p></o:p></p> <p>HTML5 adds to the description of the <img border=0 width=32 height=32 id="_x0000_i1025" src="cid:image004.png@01CB0E52.875D0AC0">tag's src attribute to instruct browsers not to make an additional request in section 4.8.2: <o:p></o:p></p> <p class=MsoNormal>The src attribute must be present, and must contain a valid URL referencing a non-interactive, optionally animated, image resource that is neither paged nor scripted. If the base URI of the element is the same as the document's address, then the src attribute's value must not be the empty string. <o:p></o:p></p> <p class=MsoNormal>Hopefully, browsers will not have this problem in the future. Unfortunately, there is no such clause for <script src=""> and <link href="">. Maybe there is still time to make that adjustment to ensure browsers don't accidentally implement this behavior. <o:p></o:p></p> <p>This rule was inspired by Yahoo!'s JavaScript guru Nicolas C. Zakas. For more information check out his article "<a href="http://www.nczonline.net/blog/2009/11/30/empty-image-src-can-destroy-your-site/">Empty image src can destroy your site</a>". <o:p></o:p></p> <p><a href="http://developer.yahoo.com/performance/rules.html#page-nav">top</a><o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> </div> Unknownnoreply@blogger.com2tag:blogger.com,1999:blog-1556630026494207117.post-32895119753329553382010-06-17T07:22:00.000-07:002010-06-17T07:26:28.214-07:00String Format for DateTime<div class=Section1> <h1>String Format for DateTime [C#]<o:p></o:p></h1> <p>This example shows how to format <a href="http://msdn2.microsoft.com/en-us/library/system.datetime.aspx">DateTime</a> using <a href="http://msdn2.microsoft.com/en-us/library/system.string.format.aspx">String.Format</a> method. All formatting can be done also using <a href="http://msdn2.microsoft.com/en-us/library/zdtaw1bw.aspx">DateTime.ToString</a> method.<o:p></o:p></p> <h2>Custom DateTime Formatting<o:p></o:p></h2> <p>There are following custom format specifiers <code><span style='font-size: 10.0pt'>y</span></code> (year), <code><span style='font-size:10.0pt'>M</span></code> (month), <code><span style='font-size:10.0pt'>d</span></code> (day), <code><span style='font-size:10.0pt'>h</span></code> (hour 12), <code><span style='font-size:10.0pt'>H</span></code> (hour 24), <code><span style='font-size:10.0pt'>m</span></code> (minute), <code><span style='font-size:10.0pt'>s</span></code> (second), <code><span style='font-size:10.0pt'>f</span></code> (second fraction), <code><span style='font-size:10.0pt'>F</span></code> (second fraction, trailing zeroes are trimmed), <code><span style='font-size:10.0pt'>t</span></code> (P.M or A.M) and <code><span style='font-size:10.0pt'>z</span></code> (time zone).<o:p></o:p></p> <p>Following examples demonstrate how are the format specifiers rewritten to the output.<o:p></o:p></p> <p class=MsoNormal>[C#]<o:p></o:p></p> <pre><span class=comments>// create date time 2008-03-09 16:05:07.123</span><o:p></o:p></pre><pre><span class=type>DateTime</span> dt = <span class=keyword>new</span> <span class=type>DateTime</span>(2008, 3, 9, 16, 5, 7, 123);<o:p></o:p></pre><pre><o:p> </o:p></pre><pre><span class=type>String</span>.Format(<span class=string>"{0:y yy yyy yyyy}"</span>, dt); <span class=comments>// "8 08 008 2008" year</span><o:p></o:p></pre><pre><span class=type>String</span>.Format(<span class=string>"{0:M MM MMM MMMM}"</span>, dt); <span class=comments>// "3 03 Mar March" month</span><o:p></o:p></pre><pre><span class=type>String</span>.Format(<span class=string>"{0:d dd ddd dddd}"</span>, dt); <span class=comments>// "9 09 Sun Sunday" day</span><o:p></o:p></pre><pre><span class=type>String</span>.Format(<span class=string>"{0:h hh H HH}"</span>, dt); <span class=comments>// "4 04 16 16" hour 12/24</span><o:p></o:p></pre><pre><span class=type>String</span>.Format(<span class=string>"{0:m mm}"</span>, dt); <span class=comments>// "5 05" minute</span><o:p></o:p></pre><pre><span class=type>String</span>.Format(<span class=string>"{0:s ss}"</span>, dt); <span class=comments>// "7 07" second</span><o:p></o:p></pre><pre><span class=type>String</span>.Format(<span class=string>"{0:f ff fff ffff}"</span>, dt); <span class=comments>// "1 12 123 1230" sec.fraction</span><o:p></o:p></pre><pre><span class=type>String</span>.Format(<span class=string>"{0:F FF FFF FFFF}"</span>, dt); <span class=comments>// "1 12 123 123" without zeroes</span><o:p></o:p></pre><pre><span class=type>String</span>.Format(<span class=string>"{0:t tt}"</span>, dt); <span class=comments>// "P PM" A.M. or P.M.</span><o:p></o:p></pre><pre><span class=type>String</span>.Format(<span class=string>"{0:z zz zzz}"</span>, dt); <span class=comments>// "-6 -06 -06:00" time zone</span><o:p></o:p></pre><pre><o:p> </o:p></pre> <p>You can use also <strong>date separator</strong> <code><span style='font-size:10.0pt'>/</span></code> (slash) and <strong>time sepatator</strong> <code><span style='font-size:10.0pt'>:</span></code> (colon). These characters will be rewritten to characters defined in the current <a href="http://msdn2.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.dateseparator.aspx">DateTimeForma­tInfo.DateSepa­rator</a> and <a href="http://msdn2.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.timeseparator.aspx">DateTimeForma­tInfo.TimeSepa­rator</a>.<o:p></o:p></p> <p class=MsoNormal>[C#]<o:p></o:p></p> <pre><span class=comments>// date separator in german culture is "." (so "/" changes to ".")</span><o:p></o:p></pre><pre><span class=type>String</span>.Format(<span class=string>"{0:d/M/yyyy HH:mm:ss}"</span>, dt); <span class=comments>// "9/3/2008 16:05:07" - english (en-US)</span><o:p></o:p></pre><pre><span class=type>String</span>.Format(<span class=string>"{0:d/M/yyyy HH:mm:ss}"</span>, dt); <span class=comments>// "9.3.2008 16:05:07" - german (de-DE)</span><o:p></o:p></pre><pre><o:p> </o:p></pre> <p>Here are some examples of custom date and time formatting:<o:p></o:p></p> <p class=MsoNormal>[C#]<o:p></o:p></p> <pre><span class=comments>// month/day numbers without/with leading zeroes</span><o:p></o:p></pre><pre><span class=type>String</span>.Format(<span class=string>"{0:M/d/yyyy}"</span>, dt); <span class=comments>// "3/9/2008"</span><o:p></o:p></pre><pre><span class=type>String</span>.Format(<span class=string>"{0:MM/dd/yyyy}"</span>, dt); <span class=comments>// "03/09/2008"</span><o:p></o:p></pre><pre><o:p> </o:p></pre><pre><span class=comments>// day/month names</span><o:p></o:p></pre><pre><span class=type>String</span>.Format(<span class=string>"{0:ddd, MMM d, yyyy}"</span>, dt); <span class=comments>// "Sun, Mar 9, 2008"</span><o:p></o:p></pre><pre><span class=type>String</span>.Format(<span class=string>"{0:dddd, MMMM d, yyyy}"</span>, dt); <span class=comments>// "Sunday, March 9, 2008"</span><o:p></o:p></pre><pre><o:p> </o:p></pre><pre><span class=comments>// two/four digit year</span><o:p></o:p></pre><pre><span class=type>String</span>.Format(<span class=string>"{0:MM/dd/yy}"</span>, dt); <span class=comments>// "03/09/08"</span><o:p></o:p></pre><pre><span class=type>String</span>.Format(<span class=string>"{0:MM/dd/yyyy}"</span>, dt); <span class=comments>// "03/09/2008"</span><o:p></o:p></pre><pre><o:p> </o:p></pre> <h2>Standard DateTime Formatting<o:p></o:p></h2> <p>In <a href="http://msdn2.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.aspx">DateTimeForma­tInfo</a> there are defined standard patterns for the current culture. For example property <a href="http://msdn2.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.shorttimepattern.aspx">ShortTimePattern</a> is string that contains value <code><span style='font-size:10.0pt'>h:mm tt</span></code> for <strong>en-US</strong> culture and value <code><span style='font-size:10.0pt'>HH:mm</span></code> for <strong>de-DE</strong> culture.<o:p></o:p></p> <p>Following table shows patterns defined in <a href="http://msdn2.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.aspx">DateTimeForma­tInfo</a> and their values for en-US culture. First column contains format specifiers for the <a href="http://msdn2.microsoft.com/en-us/library/system.string.format.aspx">String.Format</a> method.<o:p></o:p></p> <table class=MsoNormalTable border=0 cellpadding=0> <tr> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal align=center style='text-align:center'><b>Specifier</b><b><span style='font-size:12.0pt'><o:p></o:p></span></b></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal align=center style='text-align:center'><b>DateTimeFormatInfo property</b><b><span style='font-size:12.0pt'><o:p></o:p></span></b></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal align=center style='text-align:center'><b>Pattern value (for en-US culture)</b><b><span style='font-size:12.0pt'><o:p></o:p></span></b></p> </td> </tr> <tr> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal><code><span style='font-size:10.0pt'>t</span></code><span style='font-size:12.0pt'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal>ShortTimePattern<span style='font-size:12.0pt'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal><code><span style='font-size:10.0pt'>h:mm tt</span></code><span style='font-size:12.0pt'><o:p></o:p></span></p> </td> </tr> <tr> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal><code><span style='font-size:10.0pt'>d</span></code><span style='font-size:12.0pt'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal>ShortDatePattern<span style='font-size:12.0pt'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal><code><span style='font-size:10.0pt'>M/d/yyyy</span></code><span style='font-size:12.0pt'><o:p></o:p></span></p> </td> </tr> <tr> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal><code><span style='font-size:10.0pt'>T</span></code><span style='font-size:12.0pt'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal>LongTimePattern<span style='font-size:12.0pt'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal><code><span style='font-size:10.0pt'>h:mm:ss tt</span></code><span style='font-size:12.0pt'><o:p></o:p></span></p> </td> </tr> <tr> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal><code><span style='font-size:10.0pt'>D</span></code><span style='font-size:12.0pt'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal>LongDatePattern<span style='font-size:12.0pt'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal><code><span style='font-size:10.0pt'>dddd, MMMM dd, yyyy</span></code><span style='font-size:12.0pt'><o:p></o:p></span></p> </td> </tr> <tr> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal><code><span style='font-size:10.0pt'>f</span></code><span style='font-size:12.0pt'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal><em><span style='font-family:"Calibri","sans-serif"'>(combination of </span></em><code><i><span style='font-size:10.0pt'>D</span></i></code><em><span style='font-family:"Calibri","sans-serif"'> and </span></em><code><i><span style='font-size:10.0pt'>t</span></i></code><em><span style='font-family: "Calibri","sans-serif"'>)</span></em><span style='font-size:12.0pt'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal><code><span style='font-size:10.0pt'>dddd, MMMM dd, yyyy h:mm tt</span></code><span style='font-size:12.0pt'><o:p></o:p></span></p> </td> </tr> <tr> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal><code><span style='font-size:10.0pt'>F</span></code><span style='font-size:12.0pt'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal>FullDateTimePattern<span style='font-size:12.0pt'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal><code><span style='font-size:10.0pt'>dddd, MMMM dd, yyyy h:mm:ss tt</span></code><span style='font-size:12.0pt'><o:p></o:p></span></p> </td> </tr> <tr> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal><code><span style='font-size:10.0pt'>g</span></code><span style='font-size:12.0pt'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal><em><span style='font-family:"Calibri","sans-serif"'>(combination of </span></em><code><i><span style='font-size:10.0pt'>d</span></i></code><em><span style='font-family:"Calibri","sans-serif"'> and </span></em><code><i><span style='font-size:10.0pt'>t</span></i></code><em><span style='font-family: "Calibri","sans-serif"'>)</span></em><span style='font-size:12.0pt'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal><code><span style='font-size:10.0pt'>M/d/yyyy h:mm tt</span></code><span style='font-size:12.0pt'><o:p></o:p></span></p> </td> </tr> <tr> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal><code><span style='font-size:10.0pt'>G</span></code><span style='font-size:12.0pt'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal><em><span style='font-family:"Calibri","sans-serif"'>(combination of </span></em><code><i><span style='font-size:10.0pt'>d</span></i></code><em><span style='font-family:"Calibri","sans-serif"'> and </span></em><code><i><span style='font-size:10.0pt'>T</span></i></code><em><span style='font-family: "Calibri","sans-serif"'>)</span></em><span style='font-size:12.0pt'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal><code><span style='font-size:10.0pt'>M/d/yyyy h:mm:ss tt</span></code><span style='font-size:12.0pt'><o:p></o:p></span></p> </td> </tr> <tr> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal><code><span style='font-size:10.0pt'>m</span></code>, <code><span style='font-size:10.0pt'>M</span></code><span style='font-size:12.0pt'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal>MonthDayPattern<span style='font-size:12.0pt'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal><code><span style='font-size:10.0pt'>MMMM dd</span></code><span style='font-size:12.0pt'><o:p></o:p></span></p> </td> </tr> <tr> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal><code><span style='font-size:10.0pt'>y</span></code>, <code><span style='font-size:10.0pt'>Y</span></code><span style='font-size:12.0pt'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal>YearMonthPattern<span style='font-size:12.0pt'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal><code><span style='font-size:10.0pt'>MMMM, yyyy</span></code><span style='font-size:12.0pt'><o:p></o:p></span></p> </td> </tr> <tr> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal><code><span style='font-size:10.0pt'>r</span></code>, <code><span style='font-size:10.0pt'>R</span></code><span style='font-size:12.0pt'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal>RFC1123Pattern<span style='font-size:12.0pt'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal><code><span style='font-size:10.0pt'>ddd, dd MMM yyyy HH':'mm':'ss 'GMT'</span></code> <em><span style='font-family:"Calibri","sans-serif"'>(*)</span></em><span style='font-size:12.0pt'><o:p></o:p></span></p> </td> </tr> <tr> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal><code><span style='font-size:10.0pt'>s</span></code><span style='font-size:12.0pt'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal>SortableDateTi­mePattern<span style='font-size:12.0pt'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal><code><span style='font-size:10.0pt'>yyyy'-'MM'-'dd'T'HH':'mm':'ss</span></code> <em><span style='font-family:"Calibri","sans-serif"'>(*)</span></em><span style='font-size:12.0pt'><o:p></o:p></span></p> </td> </tr> <tr> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal><code><span style='font-size:10.0pt'>u</span></code><span style='font-size:12.0pt'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal>UniversalSorta­bleDateTimePat­tern<span style='font-size:12.0pt'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal><code><span style='font-size:10.0pt'>yyyy'-'MM'-'dd HH':'mm':'ss'Z'</span></code> <em><span style='font-family:"Calibri","sans-serif"'>(*)</span></em><span style='font-size:12.0pt'><o:p></o:p></span></p> </td> </tr> <tr> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal> <span style='font-size:12.0pt'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal> <span style='font-size:12.0pt'><o:p></o:p></span></p> </td> <td style='padding:.75pt .75pt .75pt .75pt'> <p class=MsoNormal><em><span style='font-family:"Calibri","sans-serif"'>(*) = culture independent</span></em><span style='font-size:12.0pt'><o:p></o:p></span></p> </td> </tr> </table> <p>Following examples show usage of <strong>standard format specifiers</strong> in <a href="http://msdn2.microsoft.com/en-us/library/system.string.format.aspx">String.Format</a> method and the resulting output.<o:p></o:p></p> <p class=MsoNormal>[C#]<o:p></o:p></p> <pre><span class=type>String</span>.Format(<span class=string>"{0:t}"</span>, dt); <span class=comments>// "4:05 PM" ShortTime</span><o:p></o:p></pre><pre><span class=type>String</span>.Format(<span class=string>"{0:d}"</span>, dt); <span class=comments>// "3/9/2008" ShortDate</span><o:p></o:p></pre><pre><span class=type>String</span>.Format(<span class=string>"{0:T}"</span>, dt); <span class=comments>// "4:05:07 PM" LongTime</span><o:p></o:p></pre><pre><span class=type>String</span>.Format(<span class=string>"{0:D}"</span>, dt); <span class=comments>// "Sunday, March 09, 2008" LongDate</span><o:p></o:p></pre><pre><span class=type>String</span>.Format(<span class=string>"{0:f}"</span>, dt); <span class=comments>// "Sunday, March 09, 2008 4:05 PM" LongDate+ShortTime</span><o:p></o:p></pre><pre><span class=type>String</span>.Format(<span class=string>"{0:F}"</span>, dt); <span class=comments>// "Sunday, March 09, 2008 4:05:07 PM" FullDateTime</span><o:p></o:p></pre><pre><span class=type>String</span>.Format(<span class=string>"{0:g}"</span>, dt); <span class=comments>// "3/9/2008 4:05 PM" ShortDate+ShortTime</span><o:p></o:p></pre><pre><span class=type>String</span>.Format(<span class=string>"{0:G}"</span>, dt); <span class=comments>// "3/9/2008 4:05:07 PM" ShortDate+LongTime</span><o:p></o:p></pre><pre><span class=type>String</span>.Format(<span class=string>"{0:m}"</span>, dt); <span class=comments>// "March 09" MonthDay</span><o:p></o:p></pre><pre><span class=type>String</span>.Format(<span class=string>"{0:y}"</span>, dt); <span class=comments>// "March, 2008" YearMonth</span><o:p></o:p></pre><pre><span class=type>String</span>.Format(<span class=string>"{0:r}"</span>, dt); <span class=comments>// "Sun, 09 Mar 2008 16:05:07 GMT" RFC1123</span><o:p></o:p></pre><pre><span class=type>String</span>.Format(<span class=string>"{0:s}"</span>, dt); <span class=comments>// "2008-03-09T16:05:07" SortableDateTime</span><o:p></o:p></pre><pre><span class=type>String</span>.Format(<span class=string>"{0:u}"</span>, dt); <span class=comments>// "2008-03-09 16:05:07Z" UniversalSortableDateTime</span><o:p></o:p></pre><pre><o:p> </o:p></pre> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal><o:p> </o:p></p> </div> Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1556630026494207117.post-64884206383736690152010-06-17T07:21:00.000-07:002010-06-17T07:25:44.249-07:00UI culture list and codes<div class=Section1> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'This code produces the following output. This output has been cropped for brevity.</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'CULTURE SPECIFIC CULTURE</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'ar Arabic ar-SA</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'bg Bulgarian bg-BG</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'ca Catalan ca-ES</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'zh-Hans Chinese (Simplified) zh-CN</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'cs Czech cs-CZ</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'da Danish da-DK</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'de German de-DE</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'el Greek el-GR</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'en English en-US</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'es Spanish es-ES</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'fi Finnish fi-FI</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'fr French fr-FR</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'he Hebrew he-IL</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'hu Hungarian hu-HU</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'is Icelandic is-IS</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'it Italian it-IT</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'ja Japanese ja-JP</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'ko Korean ko-KR</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'nl Dutch nl-NL</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'no Norwegian nb-NO</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'pl Polish pl-PL</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'pt Portuguese pt-BR</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'rm Romansh rm-CH</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'ro Romanian ro-RO</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'ru Russian ru-RU</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'hr Croatian hr-HR</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'sk Slovak sk-SK</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'sq Albanian sq-AL</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'sv Swedish sv-SE</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'th Thai th-TH</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'tr Turkish tr-TR</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'ur Urdu ur-PK</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'id Indonesian id-ID</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'uk Ukrainian uk-UA</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'be Belarusian be-BY</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'sl Slovenian sl-SI</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'et Estonian et-EE</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'lv Latvian lv-LV</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'lt Lithuanian lt-LT</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'tg Tajik tg-Cyrl-TJ</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'fa Persian fa-IR</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'vi Vietnamese vi-VN</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'hy Armenian hy-AM</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'az Azeri az-Latn-AZ</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'zh-TW Chinese (Traditional, Taiwan) zh-TW</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'zh-CN Chinese (Simplified, PRC) zh-CN</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'zh-HK Chinese (Traditional, Hong Kong S.A.R.) zh-HK</span><span style='font-size:10.0pt; font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'zh-SG Chinese (Simplified, Singapore) zh-SG</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'zh-MO Chinese (Traditional, Macao S.A.R.) zh-MO</span><span style='font-size:10.0pt; font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'zh Chinese zh-CN</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'zh-Hant Chinese (Traditional) zh-HK</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'zh-CHS Chinese (Simplified) Legacy zh-CN</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"; color:green'>'zh-CHT Chinese (Traditional) Legacy zh-HK</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p> <p class=MsoNormal><o:p> </o:p></p> </div> Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1556630026494207117.post-4723753228619784942010-06-11T01:52:00.000-07:002010-06-11T01:55:48.727-07:00Open source web design<div class=Section1> <p class=MsoNormal><a href="http://www.oswd.org/">http://www.oswd.org/</a><o:p></o:p></p> <p class=MsoNormal><a href="http://www.nyveldt.com/misc/">http://www.nyveldt.com/misc/</a><o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> <p class=MsoNormal><o:p> </o:p></p> </div> Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1556630026494207117.post-219510763901008092010-05-27T23:25:00.000-07:002010-05-27T23:27:58.699-07:00Color Codes<div class=Section1> <p class=MsoNormal><img width=570 height=724 id="Picture_x0020_1" src="cid:image001.jpg@01CAFE58.6896A240" alt="color Codes.jpg"><o:p></o:p></p> </div> Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1556630026494207117.post-65172906287592180172010-05-24T05:11:00.000-07:002010-05-24T05:13:46.610-07:00jQuery $(document).ready and UpdatePanels?<div class=Section1> <p>An UpdatePanel completely replaces the contents of the update panel on an update. This means that those events you subscribed to are no longer subscribed because there are new elements in that update panel.<o:p></o:p></p> <p>What I've done to work around this is re-subscribe to the events I need after every update. I use <code><span style='font-size:10.0pt'>$(document).ready()</span></code> for the initial load, then this snippet below to re-subscribe every update. <o:p></o:p></p> <pre><span class=kwd>var</span><span class=pln> prm </span><span class=pun>=</span><span class=pln> </span><span class=typ>Sys</span><span class=pun>.</span><span class=typ>WebForms</span><span class=pun>.</span><span class=typ>PageRequestManager</span><span class=pun>.</span><span class=pln>getInstance</span><span class=pun>();</span><br> <br> <span class=pln>prm</span><span class=pun>.</span><span class=pln>add_endRequest</span><span class=pun>(</span><span class=kwd>function</span><span class=pun>()</span><span class=pln> </span><span class=pun>{</span><br> <span class=pln> </span><span class=com>// re-bind your jquery events here</span><br> <span class=pun>});</span><o:p></o:p></pre> <p>The <code><span style='font-size:10.0pt'>PageRequestManager</span></code> is a javascript object which is automatically available if an update panel is on the page. You shouldn't need to do anything other than the code above in order to use it as long as the UpdatePanel is on the page.<o:p></o:p></p> <p>If you need more detailed control, this event passes arguments similar to how .NET events are passed arguments <code><span style='font-size:10.0pt'>(sender, eventArgs)</span></code> so you can see what raised the event and only re-bind if needed.<o:p></o:p></p> <p>Read more about the RequestManager here: <a href="http://www.asp.net/AJAX/Documentation/Live/Tutorials/UpdatePanelClientScripting.aspx">asp.net/.../UpdatePanelClientScripting.aspx</a> (If using .NET 2.0)<o:p></o:p></p> <p>Here is the latest version of the documentation from Microsoft: <a href="http://msdn.microsoft.com/en-us/library/bb383810.aspx">msdn.microsoft.com/.../bb383810.aspx</a><o:p></o:p></p> <div class=MsoNormal align=center style='text-align:center'> <hr size=2 width="100%" align=center> </div> <p>One other option you may have, depending on your needs is to use jQuery's <a href="http://docs.jquery.com/Events/live"><code><span style='font-size:10.0pt; color:blue;text-decoration:none'>live()</span></code></a> event subscriber, or the jQuery plugin <a href="http://plugins.jquery.com/project/livequery"><code><span style='font-size:10.0pt;color:blue;text-decoration:none'>livequery</span></code></a>. These methods are more efficient than re-subscribing to DOM elements on every update. Read all of the documentation before you use this approach however, since it may or may not meet your needs. There are a lot of jQuery plugins that would be unreasonable to refactor to use <code><span style='font-size:10.0pt'>live()</span></code>, so in those cases, you're better off re-subscribing.<o:p></o:p></p> <p class=MsoNormal><a href="http://stackoverflow.com/questions/256195/jquery-document-ready-and-updatepanels">http://stackoverflow.com/questions/256195/jquery-document-ready-and-updatepanels</a><o:p></o:p></p> <p class=MsoNormal><o:p> </o:p></p> </div> Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1556630026494207117.post-70288217693448565232010-05-13T23:58:00.000-07:002011-03-04T04:46:50.492-08:00Time Boxing is an Effective Getting Things Done Strategy<div dir="ltr" style="text-align: left;" trbidi="on"><div class="Section1">Given a task, there are essentially two ways we can approach it. Either, we can work as hard as we can until it is “done” or we can fix the amount of time we have available and do the “best” we can. The latter approach is known as “<b>Time boxing</b>“.<o:p></o:p><br />
Time boxing is a very simple technique we often use in software development. It is an effective technique for tracking progress and simply getting things done. From a planning perspective, time boxing is useful, especially when things appear complex or daunting initially and we are unsure of how to begin.<o:p></o:p><br />
From a personal management perspective, I’ve found that time boxing can greatly improve our productivity and effectiveness. Because it’s simple, anyone can do it – including you. I use it when working on open ended tasks, like writing, where neither the scope or the quality is well defined.<o:p></o:p><br />
This article briefly discusses how we can apply time boxing to our daily lives and get things done.<o:p></o:p><br />
<b>What is time boxing?</b><o:p></o:p><br />
Time boxing is about fixing the time we have available to work on a given task and then doing the best we can within that time frame. So instead working on something until it is “done” in <i>one </i>sitting, we only work on it for say 30 minutes. It is either marked as done at the end of this period or we commit to another 30 minutes at a later time or another day.<o:p></o:p><br />
In software development, an agile team releases new versions of a product to the customer for testing in fixed length iterations, say weekly. The customer and the development team work together to identify the features to be included in each release based on the relative priority and complexity of each task.<o:p></o:p><br />
<b>What’s special about Time boxing?</b><o:p></o:p><br />
There are always several things competing for our time. At any moment, each of us could have hundreds of outstanding things to do. This question immediately become important – How can we ensure we get as much done as possible?<o:p></o:p><br />
I believe time boxing is special for four reasons. Firstly, by consciously being aware of time, it allows us to focus on doing the things that matter most. Secondly, it serves as a reality check on how much time we spend working on open ended tasks. Thirdly, because of the fixed time constraints, it can be an effective tool against procrastination. Finally, it allows us to work on things during the free gaps we have between our commitments and appointments.<o:p></o:p><br />
<b>Focus on doing the things that matter most</b><o:p></o:p><br />
If the time available we have is limited, a rational person should immediately think about prioritizing their outstanding tasks based on what’s important and urgent.<o:p></o:p><br />
By using time boxing and ranking our outstanding tasks, we make ourselves consciously aware of how much time we have available. This allows us to focus our energies towards things that matter most. In this way, we get things that matter most done <i>first</i>.<o:p></o:p><br />
There are many techniques for ranking tasks and I won’t go into them in this post. However, it’s worth mentioning “Quality Function Deployment” – which is a technique we use in software development and engineering to translate customer requirements into engineering specifications. In the simplest sense, for each feature, we multiply a number representing a customer’s perception of its importance by another number representing an engineer’s estimation of the complexity. The final result is ranked and the relative ordering gives us an indication of what we should implement given a certain time constraint.<o:p></o:p><br />
<b>Limiting the time spent on open ended tasks</b><o:p></o:p><br />
Do you know people who are perfectionists? Those who are constantly tweaking things to make them incrementally better or just <i>different</i>? To a certain extent, I suffer from a perfectionist personality which is why I find working on open ended tasks difficult. I’ll use some examples relating to my writing to illustrate: Should this sentence be structured in a passive voice? Does this paragraph look ok here? Are there enough anecdotes in this article?<o:p></o:p><br />
Because by their nature there is no distinction between done and not done, an arbitrary open ended task can take anywhere between 1 min and 3 weeks. Time boxing is particularly useful as a reality check when working on open ended tasks. By limiting the time we spend on a given task, as long as it is complete though not perfect, we can objectively decide when something is done. This frees us up to work on the next task.<o:p></o:p><br />
<b>Effective tool against procrastination</b><o:p></o:p><br />
In my experience, people procrastinate for two reasons – firstly, when faced with a complex task they are unsure of how to start and secondly, the prospect of having to do something they’re not particularly interested in doing.<o:p></o:p><br />
<ul type="disc"><li class="MsoNormal"><b><span style="font-family: "Calibri","sans-serif";">As a tool against complex tasks:</span></b> Time boxing is useful here because it allows us to work on complex tasks over several iterations or in bite sized chunks. For example, writing a good article is a complex task for me and it is rare to be able to find one block of time in which I can write an article from start to finish. For me, it is more effective to write as best as I can within a fixed period, constantly refining and repeating this process until I finish.<o:p></o:p></li>
<li class="MsoNormal"><b><span style="font-family: "Calibri","sans-serif";">As a tool against uninteresting things:</span></b> Time boxing is useful here because it allows us to commit to an undesirable task for only a limited amount of time. It’s a lot easier to start working on something we don’t like if we knew we only need to work on it for the next 30 minutes. For example, if you have to clean a messy house, instead of trying to get through the entire house in one go, try only doing as much as you can for 30 minutes. When you have another 30 minutes to spare another day and feel so inclined, you can continue.<o:p></o:p></li>
</ul><b>Using free gaps between commitments</b><o:p></o:p><br />
The composition of a day from person to person and day to day is different. For some of us, our calendars are completely filled with appointments and meetings. For others, our days are relatively unstructured. Irrespective of our calendars, we often have what I call “null” time. That is, gaps between commitments in which we are either waiting for something or have free brain cycles.<o:p></o:p><br />
Examples of “null” times are: At the station minutes before the train comes. In the car on a winter morning whilst waiting for the engine to warm up. At the desk, after you have kicked off a full compile on a complex codebase.<o:p></o:p><br />
Time boxing can be immensely useful during these “null” times. If you knew the train will come soon, the car will warm up in moments or the code will compile in a few minutes, you can choose to use that time effectively and work on a relatively simple task you know can be done within that short “null” time.<o:p></o:p><br />
<b>In conclusion</b><o:p></o:p><br />
Time boxing is an effective way for getting things done. By fixing the amount of time we spend on a given set of tasks, we can focus on doing the things that matter, give us motivation to start, prevent overruns and use our “null” times effectively. In contrast, if we worked on things until completion in one sitting, we’re less likely to start on complex tasks, more likely to overrun on open ended tasks and leaves us with less time and motivation to work on the next set of tasks.<o:p></o:p><br />
<a href="http://www.davecheong.com/2006/07/26/time-boxing-is-an-effective-getting-things-done-strategy/">http://www.davecheong.com/2006/07/26/time-boxing-is-an-effective-getting-things-done-strategy/</a><o:p></o:p><br />
</div></div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1556630026494207117.post-38459227906873791312010-05-12T00:56:00.000-07:002010-05-12T00:59:34.952-07:00Microsoft JScript runtime error: 'Sys' is undefined<div xmlns='http://www.w3.org/1999/xhtml'><a href='http://forum.zettacube.com/ForumHome/tabid/81/forumid/9/postid/18/scope/posts/Default.aspx'/>You received the following error when loading a page with WebDock or WebSplitter at run-time:<br /><blockquote>Microsoft JScript runtime error: 'Sys' is undefined<br /><br />The required MS ASP.NET AJAX configuration is missing. This could be resulted from adding MS ASP.NET AJAX controls to a project that was not configured for ASP.NET AJAX during initial setup.<br /><br />To resolve the issue, add the followings to the <system.web> section of web.config:<httphandlers><remove path='*.asmx' verb='*'><add type='System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' validate='false' path='*.asmx' verb='*'><add type='System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' validate='false' path='*_AppService.axd' verb='*'><add validate='false' type='System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' path='ScriptResource.axd' verb='GET,HEAD'/><httpmodules><add type='System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' name='ScriptModule'><br /><br /><br /><br />You received the following error when loading a page with WebDock or WebSplitter at run-time:<br /><br />Microsoft JScript runtime error: 'Sys' is undefined<br /><br /> <br /><br />The required MS ASP.NET AJAX configuration is missing. This could be resulted from adding MS ASP.NET AJAX controls to a project that was not configured for ASP.NET AJAX during initial setup.<br /><br /> <br /><br />To resolve the issue, add the followings to the <system.web> section of web.config:<br /><br /> <httpHandlers><br /><br /> <remove verb="*" path="*.asmx"/><br /><br /> <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/><br /><br /> <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/><br /><br /> <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/><br /><br /></httpHandlers><br /><br /><br /><httpModules><br /><br /> <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/><br /><br /></httpModules><br /></add></httpmodules></add></add></remove></httphandlers></system.web></blockquote></div>Unknownnoreply@blogger.com0