Home > Web Front-end > JS Tutorial > JavaScript performance optimization summary_javascript skills

JavaScript performance optimization summary_javascript skills

WBOY
Release: 2016-05-16 15:36:53
Original
1083 people have browsed it

With the continuous promotion of Web2.0 technology, more and more applications use JavaScript technology for processing on the client side, making the performance of JavaScript in the browser the most important usability issue faced by developers. This problem is complicated by the blocking nature of JavaScript, which means that when the browser is executing JavaScript code, it cannot do anything else at the same time. This article details how to properly load and execute JavaScript code to improve its performance in the browser.

In J2EE programming, the scripting language we come into contact with most is JavaScript. When using JavaScript, we usually consider its performance issues, so we summarize the daily summary of JavaScript performance optimization methods for query.
String splicing problems are often encountered when using JavaScript. I would like to ask if you encounter the above problems when using Java programming, how to deal with it?

NX students: Teacher, use StringBulider or StringBuffer

Teacher: The answer is correct. Using StringBuilder or StringBuffer can avoid creating too many objects and reducing system performance.

Okay, back to the topic, let’s answer the questions about how to deal with the above problems when using JavaScript.

First, let’s take a look at how NX students are handled:

<html> 
<script type="text/javascript"> 
var string="begin" 
var date = new Date() 
var begin = date.getTime() 
 
for(var i=0;i<9999999;i++){ 
  string+="abc" 
} 
alert(new Date().getTime() - begin) 
</script> 
</html> 
Copy after login

The teacher almost laughed when he saw the way NX students achieved it. This kind of garbage implementation will really ruin your reputation for life.
The teacher said with a smile: Your implementation method is equivalent to the level of a primary school student, it is just a random combination of a bunch of junk letters. After saying that, I heard Teacher SB typing the code on the keyboard quickly. Before the NX students could react, the teacher had already completed the code:

<html> 
<script type="text/javascript"> 
var string="begin"; 
var string01=["begin"]; 
var date = new Date(); 
var begin = date.getTime(); 
for(var i=0;i<55555555;i++){ 
  //string+="abc"; 
  string01.push("abc"); 
} 
var result = string01.join(""); 
alert(new Date().getTime() - begin); 
</script> 
</html> 
Copy after login

By comparing the running of the above codes, the performance of the teacher's code is significantly better than that of the NX student's code. The NX student's code often causes IE to crash.
When the NX students saw the results of running the code, they immediately admired the teacher and decided to learn from the teacher humbly and constantly improve themselves...
Although this story has come to an end, the JavaScript journey of teachers and NX students continues...

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template