- Learn asynchronous programming
- Gzip compression
- Define variables locally
Whenever you call a certain function, the variables that are used to define that function are stored inside. Variables can be categorized into two types.
- Local variables that are defined only within themselves.
- Global variables that are used throughout the script.
At the time when you’re calling a function, the browser does an activity which is termed as scope lookup. With the increase in the number of scopes in the scope chain, there’s also an increase in the amount of time taken to access variables that are outside the current scope.
- Keep codes light and small
To maintain the high performance of mobile applications, it’s essential that you keep the code as light and compact as possible. Keeping codes small would reduce the latency and increase the speed.
Another method to optimize the app performance is by shrinking and diminishing various JS files into one.
- Avoid unwanted loops
- Event Delegation implementation
Event Delegation makes it easier to use a single event handler which helps in efficient management of a type of event for the entire page. In the absence of Event Delegation, large web applications can stop due to the presence of several event handlers. Event Delegation comes with many perks such as: less functionality to manage, less memory required to process, and fewer ties between DOM and code.
- Minimize DOM Access
- Specify the execution context
- Use tools that detect problems
In Chrome’s main menu, there’s an option of ‘More Tools’ which shows you the memory and the CPU usage by each tab.
- Implement the various optimizations
To solve all the tasks with optimal data structures, you must always use the algorithms that have the least complexity.
a.Get the same results with fewer calculations by rewriting algorithms.
b.Avert recursive calls
c.Put in calculations, calls, and variables for all the repeated functions
d.Simplify mathematical formulas
e.Use search arrays to get a value which is based on another rather than that of a case
f.statement or a switch.
g.Take advantage of speculative execution of processors by creating conditions that are likely to be true.