 |
Tips to save client's bandwidth
Posted by ahashim on March 21, 2007 at 07:08 AM | Comments (3)
http://egjug.org/hashimblog/2007/03/20/tips-to-save-clients-bandwidth/
In this post, I will write about the client/server bandwidth saving. In some countries, the cost of the Internet is based on the bandwidth consumption, you pay for the number of MB's you have used as traffic, so, if there is a website which contains pages with large size, you will consume the client bandwidth! Also the request will take long time because of the large size of the page. People always talking about saving server bandwidth which is good, but it is important too to save the client's bandwidth.
How can I save the client's bandwidth?
- Don't use images instead of text. Write the text and use CSS and javascript to add styles and effects for the text. For example, if you want to make a link to your homepage, some people use graphics package to write the word 'Home' and add effects, background color, borders..etc. All this staff can be done by CSS and JavaScript with a great feature "you can change the text without need to use any graphics package". So, it is very important point to replace images with text as much as possible.
- Don't use background image if it is blank, else use CSS background color.
- Don't use a big image as background, try to make a small on and repeat is using CSS.
- Don't write HTML comments in your code, instead, write server side comments in JSP, PHP ...etc code.
HTML comments <!-- comments -->
JSP comments <%--comments --%>
<?php
//comments
?>
- Don't copy-past from any word processor. The word processor like Microsoft Word add extra not-standard code, check this bulk of code
<p class="MsoNormal" dir="ltr" style="text-align: left; unicode-bidi: embed"><span style="font-size: 10pt; color: black">Test
the Microsoft Words HTML code!</span><span dir="rtl" lang="AR-SA"><o:p></o:p></span>I want just to write a statement "Test the Microsoft Words HTML code!" without any styles but the word add intelligent code :)
- Don't make inline CSS, move it to a file. Don't repeat the styles and reuse those in the common CSS. For example, you will repeat the same style for every item in a list like that
<ul>
<li style="color:#fffaaa;font-size:20;">1</li>
<li style="color:#fffaaa;font-size:20;">2</li>
<li style="color:#fffaaa;font-size:20;">3</li>
<li style="color:#fffaaa;font-size:20;">4</li>
</ul>
While you can make
.listItemStyle
{
color:#fffaaa;
font-size:20;
}
and the list will be
<ul>
<li class="listItemStyle">1</li>
<li class="listItemStyle">2</li>
<li class="listItemStyle">3</li>
<li class="listItemStyle">4</li>
</ul>
This will keep your code clean and easy to use. The code will be reusable and easy to maintain.
- Don't make inline Javascript, move it to a file. This will promote reusability and maintainability.
- Use client side validatoin with JavaScript before submitting the data to the server. So, if there is an error in the data, you will not submit and back again.
- Use AJAX to send partial requests to the server. For example, if you have 2 dropdown, one for the country and another for the city and want to load the cities of the countries choose by the user, no need to submit the complete form, just send request with the country and use the returned data from the server to update the DOM of the page.
- Use JavaScript and CSS compressor to compress the javascript and css files, it will be sent to the client, so try to minimize the size as much as possible.
The CSS compressor can reduce the size of the CSS files. You can use the DOJO compressor or any other javascript compressor.
- Use valid XHTML code to make sure that your code is correct.
- Use compression in the webserver/application server used in your application, this will compress the request/response and will save both client and servers's bandwidth. This may have a performance impact. An example for tomcat configuration:
<Connector port="8080" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true"
compression="no"
/>
You will need to add to this four attributes:
compression="force"
compressionMinSize="2048"
noCompressionUserAgents="gozilla, traviata"
compressableMimeType="text/html,text/xml"
Notice that there is a list of compressible MIME types. Basically:
* compression="no" means nothing gets compressed.
* compression="yes" means only the compressible MIME types get compressed.
* compression="force" means everything gets compressed (assuming the client accepts gzip and the response is bigger than compressionMinSize)You can test your application compression http://www.port80software.com/products/httpzip/compresscheck
- Use the ZipOutputStream as a resonse output stream if you will return to the user a big plain text file. This will compress the file on the server and send it, the client's browser will extract it.
String encoding = request.getHeader("Accept-Encoding");
OutputStream out = null;
if (encoding != null && encoding.indexOf("gzip") != -1) {
response.setHeader("Content-Encoding", "gzip");
out = new GZIPOutputStream(response.getOutputStream());
}
else if (encoding != null && encoding.indexOf("compress") != -1) {
response.setHeader("Content-Encoding", "compress");
out = new ZipOutputStream(response.getOutputStream());
}
else if (encoding != null && encoding.indexOf("deflate") != -1) {
response.setHeader("Content-Encoding", "deflate");
out = new DeflaterOutputStream(response.getOutputStream(), new Deflater(
Deflater.BEST_COMPRESSION, false));
}
else {
out = response.getOutputStream();
}
out.write(".....");
- Optimize your resources (images, flash).
Another great tip from the comments below, use the Cache-control headers to cache the static resources on the client side for a specific duration. A perfect example is there
OnJava.
This will result in save the client/server bandwidth and develop more fast web application.
References:
http://www.cssdrive.com/index.php/main/csscompressor/
http://dojotoolkit.org/docs/compressor_system.html
http://javascriptcompressor.com/
http://java.sun.com/j2se/1.4.2/docs/api/java/util/zip/ZipOutputStream.html
http://httpd.apache.org/docs/2.0/mod/mod_deflate.html
http://www.codinghorror.com/blog/archives/000059.html
http://tomcat.apache.org/tomcat-5.5-doc/config/http.html
http://fmarcia.info/jsmin/test.html
Bookmark blog post: del.icio.us Digg DZone Furl Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment
-
You forgot the most important one with using cache control headers and ETag headers to prevent requests for the same data multiple times for (static) data.
Posted by: jhook on March 22, 2007 at 09:59 AM
-
Amen to support for caching, and this, together with Accept-Encoding support for compression, should be at the top of the list. All the other "tricks" pale in comparison.
Even a lot of dynamically generated data is "static", if that makes any sense. For example, a rendering of immutable or seldom modified records could be cached. Said another way: just because some content is rendered by a JSP instead of stored in a static HTML file doesn't necessarily mean it's not cacheable. Proper use of GET rather than POST, and intelligently crafted URLs and parameters facilitate caching too.
Thanks for the blog, Ahmed. I hope to see more beautiful, lean pages snapping to attention after applying these tips.
Posted by: erickson on March 22, 2007 at 12:11 PM
-
门诊
癌症
肿瘤
胃癌
肺癌
肝癌
白血病
鼻咽癌
大肠癌
宫颈癌
膀胱肿瘤
食管癌
乳腺癌
抗癌新药
肾癌
胰腺癌
胆囊癌
甲状腺癌
脑瘤
恶性黑色素瘤
恶性淋巴瘤
阴道恶性肿瘤
卵巢恶性肿瘤
绒毛膜癌
子宫内膜癌
阴茎癌
睾丸肿瘤
前列腺癌
癌症
肿瘤
胃癌
肺癌
肝癌
白血病
鼻咽癌
大肠癌
宫颈癌
膀胱癌
食管癌
食道癌
乳腺癌
抗癌新药
肾癌
胰腺癌
胆囊癌
直肠癌
甲状腺癌
脑膜瘤
恶性黑色素瘤
恶性淋巴瘤
阴道恶性肿瘤
卵巢癌
绒毛膜癌
子宫内膜癌
阴茎癌
睾丸肿瘤
前列腺癌
肝病
肝病治疗
乙肝
乙型肝炎
丙肝
脂肪肝
肝纤维化
肝硬化
肝性脑病
紫杉醇注射液
开普拓
美罗华
赫赛汀
天地欣
香菇多糖
艾普升
宁得朗
康士得
诺雷得
瑞宁得
芙瑞
瑞婷
法乐通
易瑞沙
多吉美
特罗凯
泰勒宁
路盖克
皮肤病
银屑病|牛皮癣
白癜风
尖锐湿疣
脱发
痤疮|青春痘
皮炎
灰指甲
疤痕|瘢痕
疱疹
系统性红斑狼疮
色斑
艾滋病
丽科杰
里亚美
明欣利迪
疣迪
明竹欣
无为白癜风胶囊
维阿露
白癜净
达霏欣
狼疮丸
适今可
克银丸
云香十五味丸
化瘀祛斑胶囊
疤痕敌
每宜
新药网
肺癌
鼻咽癌
食道癌
胃癌
肝癌
大肠癌
乳腺癌
卵巢癌
膀胱癌
白血病
胰腺癌
宫颈癌
神经内科
癫痫
帕金森病
老年性痴呆
脑血管病
多发性硬化症
偏头痛
小儿脑瘫
心血管
高血压
高血脂症
心血管疾病
精神心理
精神分裂症
抑郁症|焦虑症|躁抑症
强迫症
睡眠障碍
多动症
神经衰弱
糖尿病
类风湿
瑞美隆
肉蔻五味丸
喜普妙
怡诺思
优克
恩经复
申捷
重塑杰
施捷因
神经妥乐平
七十味珍珠丸
珊瑚七十味丸
郝智片
参蛇偏瘫胶囊
扎冲十三味丸
洛斯宝
安理申
金思平
泰舒达
珂丹
利鲁唑
力如太
静灵口服液
地牡宁神口服液
健儿贴
哈伯因
肺癌
小细胞肺癌
非小细胞肺癌
肺膦癌
肺腺癌
香菇多糖
瑞宁得
复方斑蝥胶囊
金复康口服液
癌症博客
癌症博客
癌症博客
癌症博客
癌症博客
癌症博客
中国癌症之家
癌症博客
癌症博客
癌症博客
癌症博客
癌症博客
癌症博客之家
癌症博客
癌症博客
癌症博客
癌症博客
中国癌症博客
癌症博客
癌症博客
癌症博客
癌症博客
癌症博客
癌症博客
癌症信息博客
癌症博客
癌症博客
癌症博客
癌症博客
癌症博客
癌症博客
癌症博客
癌症博客
癌症博客
癌症博客
癌症博客网
癌症博客
癌症博客中国人
癌症博客
癌症博客
癌症博客
癌症博客
中国癌症博客
癌症博客
癌症博客
癌症博客
癌症博客
特罗凯博客
特罗凯博客
特罗凯博客
特罗凯博客
特罗凯博客
特罗凯博客
特罗凯博客
特罗凯博客
特罗凯博客
抗癌博客
抗癌博客
抗癌博客
抗癌博客
抗癌博客
抗癌博客
抗癌博客
抗癌博客
抗癌博客
抗癌博客
抗癌博客
特罗凯博客
特罗凯博客
特罗凯博客
特罗凯博客
特罗凯博客
特罗凯博客
特罗凯博客
特罗凯博客
特罗凯博客
易瑞沙博客
易瑞沙博客
易瑞沙博客
易瑞沙博客
易瑞沙博客
易瑞沙博客
易瑞沙博客
易瑞沙博客
易瑞沙博客
易瑞沙博客
易瑞沙博客
易瑞沙博客
易瑞沙博客
Posted by: bxz on August 17, 2007 at 01:20 AM
|