Recently the company a project on-line, often collapsed, so began to pay attention to performance issues, in the Internet to see a lot of related articles, finishing issued up. For reference.
When developing Web sites with ASP. Performance is always a matter of concern and attention, performance is not just the speed at which the program code executes, but the things that are involved in every aspect.
Take a request for ASP., from the browser to the Web site of the server to send the request started until the end of the entire page rendering in front of us, where the request passes through each step, there are different tuning methods, and the method of invocation is also many, not just common: caching, multithreading, asynchronous and so on.
The articles in this series decide on two big aspects to tell about tuning:
Foreground tuning: mainly includes how to minimize the HTTP request, starting from the HTTP request, to how to load JS, CSS, how to compress the transmitted data and so on.
Background tuning: Analyze the process of ASP. NET request, and give the corresponding tuning method at each step, and give the tuning method in code organization, architecture and database operation.
Remember that when the website was just developed, the easiest and fastest thing to think about is the cache, and in some documents of Microsoft's official best practice, it is also recommended: Layer-by-layer caching (in the data storage layer, DAL,BLL,UI, etc.). Then in the site on the "cache everywhere", the final really unsatisfactory.
Another common optimization is for databases: such as minimizing subqueries, using join joins, and indexing fields that often require queries. Indeed, these are very general and good rules.
There is also an understanding that, in optimizing performance, if you choose to optimize the code and database, often optimize the operation of the database will result in more good results, unfortunately: in the project (at least in some of the projects I developed), the database is just a data storage device, that's all, Does not play a powerful role in the database. Therefore, it is recommended to be familiar with the internal query and storage mechanisms of the database, after all, many times the developer is also working as a DBA (many companies do not have a formal DBA).
And in the project when we design the database, especially the table field, it is necessary to consider some, many people suggest that the length of the table field is not too long, this is common suggestions, but why? In fact, this needs to know some of the internal storage mechanism of the database: when the database (SQL SERVER) is saved, the data is in the "page" as the smallest unit, each page has 8 k size, if you have a table of data more than 8K, then the table data will be divided into several pages to save, So in the data query, it is necessary to cross-page query, cross-page is required performance consumption, if the data are on a page, then the speed is certainly faster.
So, to optimize the site, you need to know where the performance is consumed.
When optimizing a website, is not blind generalize, generally there are two kinds of situations:
1, the site already exists, and run, and now to optimize.
2. A new website is being developed from scratch.
If it is the first case, then the first to find out the bottleneck of the site performance, from the foreground to the background of the request processing, until the final page rendering, will have to step-by-step review.
In the second case, it might be a little bit better, and the site is now completely under our control, and all of the development and design processes can be optimized using a number of optimization principles.
Optimization is not necessarily a code rewrite or make a lot of changes, the optimization of a little bit of accumulation, like the refactoring of code, is a cumulative effect. For example, in the beginning of the page to load the JS script, or at the end of the page to load the JS script, sometimes just simply adjust the loaded file, or asynchronous loading script, or through the CDN transfer scripts and so on, the performance is improved. Performance improvements are also not cost-free, and some are very small, such as simply loading scripts into the page at the end of the price, such as buying server devices such as content Delivery Network (CDN) to transfer static files (js,css,image) to the client. So, optimization requires a trade-off strategy.
Here are some common problems and solutions for JavaScript interaction with C #
1. How do I access C # functions in JavaScript?
2. How do I access C # variables in JavaScript?
3. How do I access the existing variables of JavaScript in C #?
4. How do I access JavaScript functions in C #?
Question 1 answers are as follows:
The functions in the C # code are executed in the JavaScript function:
Method One: 1, first set up a button, in the background will be called or processed content written in Button_Click;
2, write a JS function in the foreground, the content is
3, in the foreground or background call JS function, fire click event, equal access to the background C # function;
Method Two: 1, function declaration is public
Background code (change public to protected also can)
1 public string SS () 2 {3 return ("a"); 4}
2, in the HTML can be called
Foreground script
1 <script language=javascript> 2 3 var a = "<%=ss ()%>"; 4 5 alert (a); 6 7 </script>
Method Three: 1,
1 <script language= "JavaScript" > 2 3 <!-- 4 5 function __dopostback (Eventtarget, eventargument) 6 7 { 8 9 var theform = document. Form1; Refers to the form of runat=server theform.__eventtarget.value = Eventtarget; Thefrom.__eventargument.value = eventargument; Theform.submit (); +--</script> <input id= "Button1" type= "button" Name= "Button1" value= "buttons" on click= "Javascript:__dopostback (' Button1 ', ')" >
Method Four:
1 <script language= "JavaScript" > 2 3 function Submitkeyclick () 4 5 { 6 7 if (EVENT.K Eycode = = 8 9 {Ten event.cancelbubble = true; Event.returnvalue = false; 14 15 Document.all.funname.value= "The name of the function you want to invoke"; Document.form[0].submit (); * </script> <input onkeypress= "Submitkeyclick ()" id= "AAA" type= "text" > 26 <input type= "hidden" name= "Funname" >〈! --Used to store the function you want to call--〉
In. cs There are:
Public Page_onload () {if (! Page.ispost ()) {string strfunname=request.form["Funname"]!=null?) request.form["Funname"]: ""; Determines which function switch (strfunname) {case "Enter ()" is called based on the returned value: Enter ();//Call the function break; Case "Other"://Call other function break; Default://Call http://www.cnblogs.com/sosoft/break function; }}} public void Enter () {//... such as calculating a value}
Question 2: How do I access C # variables in JavaScript?
The answers are as follows:
Method One: 1, through the page to hide the domain access
Method Two: 1, such as the background defines the public STRING N; The format of the variable referenced in the foreground JS is "or" + + "
Method Three: 1, or you can register a script on the page after the server-side variable is assigned a value
"<script language= ' JavaScript ' >var temp=" + tmp + "</script>"
TMP is a background variable, and then JS can directly access the temp to get the value.
3. How do I access the existing variables of JavaScript in C #?
The answers are as follows:
Method One: 1, the foreground uses the static text control to hide the field, writes the JS variable value into it, 2, the backstage uses request["the ID"] to obtain the value;
Method Two: You can use a cookie or session
Question 4: How do I access JavaScript functions in C #?
The answers are as follows:
Execute JavaScript functions in C # code:
Method One: 1,
Page.registerstartupscript ("GGG", "" ");
Method Two: Use the literal class, and then
Online site Optimization Experience