The official website of Bipul Raman

JavaScript libraries: When to use & How to use

1 comment

JavaScript is now one of the most extensively used scripting language in the field of web application. There are a lot of JavaScript frameworks available over the internet and I have seen a lot of developers using that blindly, means without caring about the impact on performance of the web application.

Here I have mention few points which may help you to decide when to use and how to use JavaScript and its framework. These are very common points yet quite useful for beginners.
  1. If only few lines of JavaScript is required, Use it in the page within script tags. No need to put in a separate JS file and referencing it.
  2. If some common JavaScript function is used in multiple pages, it is better to use in a separate JavaScript file instead of embedding in the same page.
  3. Use framework only when you are going to use it extensively. I have seen many people just for few common operations they use jQuery framework which affects the web application performance.
  4. If a framework has been used in multiple pages, Load that framework in master page/ common layout page (if applicable) instead of loading every time in each pages. If it is used in only one pages, then load it by referring within that page itself
  5. Try to use CDN (Content Delivery Network) as much as possible for any framework. CDN will reduce your load on the web hosting server where your application is hosted.
  6. Never write any page specific code in document ready function in that file which is getting called through master page /common layout page. If any JS code which are supposed to run during  page load on a specific page, Write it within the page itself in on-load function or document ready function.
  7. If any JS is not required/used on page load, Its better to load it from end of the page instead of loading from head section of the page.
  8. Always remember, JavaScript is naked script in your web application. Never write any business logic in JavaScript. If you are writing any field validations, Make sure that you have written codes for validation in back-end as well.
  9. JavaScript can be altered through injecting scripts via browser. Make sure that any alteration in the code must not affect the security and integrity of your application.
  10. Always use try catch and console log statements to handle and get exact error details.
  11. Implement all the best practices and coding standards preferred for web programming languages.
  12. Whenever you write a piece of code, try to justify yourself if that code is necessary or not. Do not unnecessarily code too much. Try to reuse functions. Write functions in such a way so that to increase it re-usability.

1 comment :