September 28, 2015

Javascript Best Practise

#1 - Reduce the HTTP request
Every HTTP request is over head on the server which slow the response time. Always keep the HTTP request to smaller

#2 - Placement of the JS File
<script> tag on the page will block the rendering of the HTML page until the execution of the code in inline <script> tag is done or the JS file is loaded. It is the best practise to place the JS files at the bottom of the page or use Defer or other loading method of JS file to avoid the loading of the page.

#3- Combine JS files
If you are having multiple JS file combine them to one. So, that we have only 1 http request. It is always better to load one 10KB file instead of hitting 25kb four times HTTP request.

#4 - Minify your JS file
The larger the file, longer time it will take to execute and which will result in again slowing the response time. Hence, make it the best practise to minify your JS file

#5- Cache the JS file
It is always the best approach to cache the JS file request

#7- Compress the JS file using gzip encoding

#6- Use CDN
It will not only improve performance but also handle caching and compression

Comments, suggestions and feedbacks are welcome.

Happy Learning!!

No comments: