JavaScript is an aesthetic language used for web development. There are many special effects in this language that make user experience an improved and memorable one. So one thing should always be kept in central focus by the web developers- improvement of user experience. JavaScript offers many useful and clever ways in which a site may be improved from the perspective of user interface. Here are a few smart Javascript techniques which can help you improve UI performance.
1) insert AdjacentHTML instead of innerHTML- The extremely popular innerHTML has been transformed into a brand new avatar in the form of the optimized and fine grained version called insert AdjacentHTML. Since the position is specified, the element used upon is not re-parsed by this API; in fact extra serialization step is avoided which makes it much faster than the other manipulation. In approaches where the markup has to be appended continuously to a module or page this is very effective. Compared to innerHTML, insert AdjacentHTML is 100% faster.
2) requestAnimationFrame instead of setInterval- As compared to the conventional intervals and times, a more efficient as well as optimized approach is the use of requestAnimationFrame API while building animation based on JavaScript. The timer calculations are offloaded by this API to determine the timing of the upcoming UI/DOM style changes in the browser. It takes away from the responsibility of the developer to decide when the screen needs a repainting. Replacement with requestAnimationFrame will lead to smoother animations as well as saving of battery life in mobile devices if the content is viewed over there.
3) if-else instead of try-catch- Unforeseen runtime related errors and exceptions can be handled efficiently through the mechanism of try-catch. But a performance penalty is imposed by the blocks in JavaScript which is especially the case when used in recursive functions or iterations. On replacing try-catch with if-else conditions, each and every error handling will be taken care of; the resultant code will be much better as well as more efficient.
4. Improving startup performance- Try distinguishing between 'right after startup' and 'startup' and try to move to using 'right after startup' as much as possible. Design the UI in manner that as soon as the data changes it automatically updates. This result in saving of a lot of time and you will not have to wait for a long time so that everything may be ready. Some things are there which cannot be done right after startup; in short you will be able to perceive the startup time. To reduce the loading time you can combine CSS or Cascading Style Sheets. This will be especially perfect if many UI controls are in use. The loading time of almost 50 files can be reduced to near about 25% with the correct code combination. You can also try code minification; the benefits will be code-dependent- like 10-25%. To guarantee great startup one must-have is Lazy loading. To load a code of 10 MB, almost 10 seconds will be needed. But to showcase an initial view 100K is needed, if not more which means a loading time of 1 second. With lazy loading the 9 seconds may be deferred and scattered.
5) JQuery Autotab- It is often remarked that this feature is a must-have for all forms on internet. This may be a small thing but it provides a much better experience to the user when he or she is filling out forms and items, especially if there is the need to fill up things such as social security numbers, etc. If the form has jQuery then autotabs are added by the jQuery Autotab function.
There are so many options in JavaScript that can improve user experiences drastically like sliding top panel, social history, context highlighting web forms, magic zoom, password strength meter, etc. But while using them, in order to make them actually very effective, thoughtful implementation and restraint must be practiced. A perfect balance has to be struck. Use techniques that will actually be applicable as well as relevant; not just for the sake of using it. This would help you leverage the benefits of Javascript application development.
We provide Javascript ajax development services. If you would like to talk to one of our expert Javascript programmers, please get in touch with us at Mindfire Solutions.
1) insert AdjacentHTML instead of innerHTML- The extremely popular innerHTML has been transformed into a brand new avatar in the form of the optimized and fine grained version called insert AdjacentHTML. Since the position is specified, the element used upon is not re-parsed by this API; in fact extra serialization step is avoided which makes it much faster than the other manipulation. In approaches where the markup has to be appended continuously to a module or page this is very effective. Compared to innerHTML, insert AdjacentHTML is 100% faster.
2) requestAnimationFrame instead of setInterval- As compared to the conventional intervals and times, a more efficient as well as optimized approach is the use of requestAnimationFrame API while building animation based on JavaScript. The timer calculations are offloaded by this API to determine the timing of the upcoming UI/DOM style changes in the browser. It takes away from the responsibility of the developer to decide when the screen needs a repainting. Replacement with requestAnimationFrame will lead to smoother animations as well as saving of battery life in mobile devices if the content is viewed over there.
3) if-else instead of try-catch- Unforeseen runtime related errors and exceptions can be handled efficiently through the mechanism of try-catch. But a performance penalty is imposed by the blocks in JavaScript which is especially the case when used in recursive functions or iterations. On replacing try-catch with if-else conditions, each and every error handling will be taken care of; the resultant code will be much better as well as more efficient.
4. Improving startup performance- Try distinguishing between 'right after startup' and 'startup' and try to move to using 'right after startup' as much as possible. Design the UI in manner that as soon as the data changes it automatically updates. This result in saving of a lot of time and you will not have to wait for a long time so that everything may be ready. Some things are there which cannot be done right after startup; in short you will be able to perceive the startup time. To reduce the loading time you can combine CSS or Cascading Style Sheets. This will be especially perfect if many UI controls are in use. The loading time of almost 50 files can be reduced to near about 25% with the correct code combination. You can also try code minification; the benefits will be code-dependent- like 10-25%. To guarantee great startup one must-have is Lazy loading. To load a code of 10 MB, almost 10 seconds will be needed. But to showcase an initial view 100K is needed, if not more which means a loading time of 1 second. With lazy loading the 9 seconds may be deferred and scattered.
5) JQuery Autotab- It is often remarked that this feature is a must-have for all forms on internet. This may be a small thing but it provides a much better experience to the user when he or she is filling out forms and items, especially if there is the need to fill up things such as social security numbers, etc. If the form has jQuery then autotabs are added by the jQuery Autotab function.
There are so many options in JavaScript that can improve user experiences drastically like sliding top panel, social history, context highlighting web forms, magic zoom, password strength meter, etc. But while using them, in order to make them actually very effective, thoughtful implementation and restraint must be practiced. A perfect balance has to be struck. Use techniques that will actually be applicable as well as relevant; not just for the sake of using it. This would help you leverage the benefits of Javascript application development.
We provide Javascript ajax development services. If you would like to talk to one of our expert Javascript programmers, please get in touch with us at Mindfire Solutions.
No comments:
Post a Comment