- asp.net mvc
- IT 관련
웹어플리케이션 client측 성능 개선 본문
웹어플리케이션 client측 성능 개선재우니 2009.02.15 21:16
웹어플리케이션 client측 성능 개선
Published: 30 Apr
Adnan Aman shows some tricks and tips to improve the performance of web applications.
In the IT world, software applications are being rapidly developed. Clients, and so employers, are just looking for those teams/individuals who can build up applications rapidly, just bothering to make their application live; but what often happens after an application goes live is that users start to use the application and it doesn’t respond well. At this point, clients start to lose users and business.
To code an application is not a big deal; I believe it can be done by virtually anyone, meaning it is not necessary to have great knowledge or experience. Improving performance of an existing application (especially an one put together rapidly) could be quite risky and could cause many ripple effects. Things must be planned first to avoid horrible results.
The following are a few points that can make a site scalable and reliable; but which may initially slow down development. I believe that overall, when maintenance and future changes are taken into account, total development time would be reduced.
1. HTTP 기반 Request 최소화
Problem 1: Serving images - no matter if they are of less than 1 KB - as separate web resources, cause separate web requests to the server, which impact performance.
- Use Image Maps to merge up images, though image Maps could only merge up those images which are in sequence, like navigation images, so it depends upon your web site/page design.
- Use Inline images. Inline images could increase your HTML page size but would cause fewer requests to the server.
- CSS Sprites can also be used to merge up images and setting their position and backgrounds.
Problem 2: Using CSS is very good practice but serving stylesheets as separate resources, thus causing separate requests, should be considered very carefully.
Problem 3: 자바스크립트 is an awesome scripting language which can be quite powerful to play with. Nonetheless, it should be used carefully not only for request size issues; but also because it can have a way of causing unpredictable performance issues.
Solution: Inline 자바스크립트 could make the HTML page heavy, so it’s preferred to serve separate .js files or a single 자바스크립트 file to keep all 자바스크립트-based scripts in a single place.
자바스크립트 files also get cached automatically by browsers, so they usually aren’t requested each time the page is loaded by the browsers.
2. HTTP 압축
HTTP Compression is used to compress contents from the web server. HTTP requests and responses could be compressed, which can result in great performance gains. Through HTTP compression, the size of the payload can be reduced by about 50%, which is great. Isn’t it?
HTTP Compression is now widely supported by browsers and web servers.
If HTTP compression is enabled on the web
server, and if the request header includes an
Accept-Encoding: gzip, deflate header, the browser supports gzip and deflate
compression mechanisms, so the response can be compressed in any of the given
formats by the web server in order to reduce the payload size. This leads to an
increase in performance. Latter that compressed response is decompressed by the
browser and rendered normally.
Following are very good links which detail HTTP Compression and their implementations:
3. 올바른 장소에 올바른 포멧의 이미지 사용하기
Problem: Normally designers use JPG or GIF formats quite randomly and ignore some other good formats to compress images.
Solution: Correct format should be used for right purpose like
4. 압축된 CSS, 자바스크립트 그리고 Images 사용하기
CSS files (.css), images and 자바스크립트 (.js) files can be compressed, as normally .css and .js files contain unnecessary spaces, comments, unnecessary code and such other things. A number of high quality (and free) utilities are available to help you pre-compress your files.
Following are a few good links for such
I have used these utilities and seen compression results of about 50% in file size reduction after using such loss-less compression, so I recommend them.
5. CSS 상단 위치 두기
The recommended approach is to put CSS links on top of the web page, as it makes the page render progressively efficient. Since users want to see the contents of a page whilst it’s loading rather than white spaces, contents/formats should be given on top. HTML Specifications clearly say to declare style sheets in the head section of a web page.
6. 자바스크립트 하단에 두기
When scripts are defined on top of the page they can take unnecessary time to load; they don’t show the contents that users are expecting after making any request to an HTTP web server. It's better to display a the HTML contents of a page, then load any scripting code (when possible, of course).
Preferably use/link up
자바스크립트-based scripts at the bottom of a web page. Alternatively
you can use the
attribute, which runs the
script at the end of page loading, but that is not the preferable approach as it
is not browser independent. For example, Firefox doesn’t support it and could
mess up with
document.write, so only use it once you fully understand the
7. Content Delivery Network: (CDN) 이용하기
When a browser makes a request to any web page – that is, he types a URL/URI of any web page or web site, a request goes through many hops (routers and computers) and then finally reaches its final destination. This happens both for requests and responses. This operation affects performance and can severely effect load time.
A Content Delivery Network implies a collection of computers, distributed all over the world, which deliver data (contents). Through a CDN you can have your website data on multiple servers distributed in different locations around the world. Distribute web application data in different places around the world so request can be served from the nearest location and save time (which means performance and money as well).
8. Ajax 적절히 사용하기
Problemm: Ajax is being increasingly used to improve usability, but oftentimes in a way which increases overall server load.
Preferably use the GET method for Ajax based Requests, because if you use POST method then the request header would be sent first, followed by the data, which basically splits the request in two steps. A single-step request can be achieved with GET if a cookie is not too long and the URL is not larger than 2k.
9. Ajax vs. Callback
Problem: Ajax is a great solution for asynchronous communication between client (web browser) and HTTP servers, but one solution can't be applied to every problem. This means that Ajax is great mechanism for sending requests to the server without making a full page postback, but what if you need to send a request to the server and don’t even need partial rendering?
Solution: best solution is Callback.
For example, if you need to check whether a user exists or not, or if a user has forgotten his/her password and you just need to send a request to the server to check if user name exist, there is no need for client-side render - just a server side operation.
10. Cookie 사이즈 줄이기
Cookies are stored on the client side to keep information about users (authentication and personalization). Since HTTP is a stateless protocol, cookies are common in web development to maintain information and state. Cookies are sent with every HTTP requests, so try to keep them low in size to minimize effects on the HTTP response.
Cookie’s size should be minimized as much as possible.
Cookies shouldn’t contain secret information. If really needed, that information should be either encrypted or encoded.
Try to minimize the number of cookies by removing unnecessary cookies.
Cookies should expire as soon as they become useless for an application.
11. 적절한 Cache 사용하기
Cache mechanism is a great way to save server round trips - and also database server round trips - as both round trips are expensive processes. By caching data we can avoid hitting them when unnecessary. Following are few guidelines for implementing caching::
Now that web technologies such ASP.NET have matured and offer such great caching capabilities, there's really no reason not to make extensive use of them.
Following are few very good links to implement caching for different types of data (static and dynamic):
12. 원본 코드보다 컴파일된 코드를 업로드 하기
Pre-compiled ASP.NET pages perform much better than source code versions. Actually pre-compilation give web sites a performance boost especially when the first request is made to a folder containing that resource.
Uploading a pre-compiled version boosts up performance since the server doesn’t need to compile a page at request-time.
Following are few good practices to gain better performance::
I hope you have learned some very good approaches and techniques to keep your web application in good shape on an HTTP server. I personally don’t think any are flat-out ignorable nor is any too difficult to implement.
As performance is a vital part of success for any web application, I have tried to be as general as possible, so every web technology (ASP.NET, asp, php, jsp, jsf and so on) can follow these tips.
|Muhammad Adnan worked on .net technologies since he started to work :D He loves to write articles, help people by means of technical problems ( if he could ;) ) and interviews He has worked on many applications from CALCULATOR application to ERP systems :P|
'닷넷관련 > ASP.NET WEBFORM' 카테고리의 다른 글
|Visual Studio 2005 툴에 신기한 썸네일(thumnail) 스크롤(scroll) 제공 (0)||2009.02.18|
|웹어플리케이션 client측 성능 개선 (0)||2009.02.15|
|ASP.NET 성능 개선 TIP 리스트 (2)||2009.02.15|
|Generic(제네릭) 할당값 정렬해서 출력하기 (0)||2009.02.14|
|ASP.NET 4.0 웹폼 - 새로운 기능 [동영상] (0)||2009.02.13|