Here are some tips for web developers about JavaScripts ;
JavaScript downloaded as source code and then interpreted by the browser.
Because of this, the speed of JavaScript code is split into two categories:
1.Download time
2.Speed of execution
Browsers download JavaScript as source code, that means all long variable names and comments are included.
Other factors increase the download time and increase the overall time it takes for the script to run .
CODE
The best size for a javascript = Single tcp/ip packet = 1160 bytes
Now how to decrease the javascript to this packet size ?
Tip(1)
Remove all comments
Although these comments are ignored by the execution process as we all know BUT
Comments increase the js size means increase download time
Also comments make it easy for anyone to get the script idea
Tip(2)
Remove tabs and spaces
Increasing readability is ok if you are tring to teach scripts in tutorials or so BUT
Browsers do not need these tabs and spaces to understand your scripts ,
So remove them
look at this
CODE
function dothis ( arg1, arg2, arg3 ) { alert(arg1 + arg2 + arg3); }
see all the spaces
CODE
function dothis(arg1,arg2,arg3){alert(arg1+arg2+arg3);}
12 spaces = 12 bytes removed !
Use semicolons (
Tip(3)
Remove all line breaks
Line breaks increase the readability of your code to prying eyes.
Removing them is a fast, easy way to make it more difficult for anyone to get your code.
Tip(4)
Replace variable names
Any variable name should be replaced with a nonsense variable name that has no meaning when read in the code.
After all, the name of the variable doesn’t matter to browsers.
Eliminate those descriptive variable names with simpler,
You dont need to name the variable i.e. myimages OR url_destination ..... etc
Just repalce url_destination with ud and myimages with mg ....... like that
Variables names now have no meaing , smaller and still working BUT
For editing a variable name do read and understand its function before changing its name .
Dont just use Find and Repalce method in a text editor
Dont forget to save a copy of the script before you start
Hope you like it
hazemmostafa

