Which is the best place to have Javascript? Should we write the code using the script tag within head tag itself or Is it best to have it in an external file? I heard that the search engine crawlers prefer external files? Is that so?
Hi R2W, I recommend you to have it in seperate file. Since doing it increases "compartmentalization" of code. It will bring following benifit to you. You can use your javascript (or some functions of it) in other pages. On the contraray, if you have same code at multiple places keeping them all in sync, as they change and grow, will become nighmare. It's better to have them seperate right from the begining. When distribution of work is between designer and programmer both can work independently. It helps in versioning also. Infact, I would encourage you to have different javascript files for different purposes. That way it will be easy to manage you code while it is chaning and growing and growing and changing . Remember to divide and rule !!! Hope this will help. Regards, Samyak