Thursday, September 4, 2008

Why use .js file for javascript?

Advantages of writing javascript code in .js file over writing the same in .aspx file under the javascript tags:

1. The code in the .js file can be re-used by different aspx and aspx.cs pages.

2. Once the application using the code is run on the client machine, the .js file sits in the cache of the client and keeps working from there - which could be something useful, specially for cases where you might want to display clock on the web page without a postback; or check network connection constantly on web page and disable the web page buttons in case there is a disconnected network instead of HTTP error messages.

3. This cache re-usage would also speed up the page loading and users of your site would also experience faster page loads.

4. Also, you can hide your javascript code from the users in this way. Users cannot see the javascript code in the .js file when they do 'View Source' on the web page.

No comments:

About Us