from: http://www.readablog.com/feed23650.aspx
//===============================
The main problem when we are using ajax framework is because of their big size. Of course, it will extremely slow down the sites load time. For example, if we use the standard jQuery, it’s almost 100Kb. It’s even more if we use the complete Prototype and Scriptaculous that will cost around 150Kb.
在我們使用ajax框架的時候,最讓我們困擾的就是這些框架文件太多了。所以,載入這些文件會非常的慢。例如:如果使用標準的(即不經壓縮的)jQuery,文件達到100Kb大小。完整的Prototype和Scriptaculous加起來更是達到了150Kb。
This is really nightmare for people who still use GPRS or the old 56kbps Dial-Up internet connection. It will takes minutes to load the sites or maybe it will takes forever because the browser usually won’t download it. Unfortunately, it’s very easy to solve this problem. Do you know that we can compress those files and reduce the size by half or more?
這對仍然使用GPRS或56kbps撥號上網的用戶來講,簡直就是夢魘。這將花去流覽器很多時間去下載甚至永遠都不會下載這些網站文檔,因為流覽器通常會不下載這樣大的文件。很不幸的是,其實解決這個問題是非常簡單的(說不幸,又說很簡單,呃……)。你知道嗎?我們可以把這些文件壓縮或者是減小到一半甚至一半以下!
There are several method to compress javascript and I think one of the most efficient method is using Gzip Compression.
在許多壓縮javascript的辦法當中,我最讓為效果最好的就是使用Gzip壓縮法了。
To implement the gzip compression for websites, first we need to gzip the Javascript files. For that purpose, we will need a gzip-compatible archiver / compressor. 7-zip is my favorite because it’s small, very fast and it’s completely free.
使用Gzip壓縮法,首先,我們要把Javascript文件壓縮為gzip文件。(要把文件壓縮為Gzip文件,就要使用到Gzip相容的壓縮工具,作者在此做一下廣告:7-zip壓縮工具,不但體積小,運行快,並且是完全免費的!)
Gzip the JavaScript file, change the “gz” extension to “jgz” for safari compatibility and upload it to the same location together with the original script. Then next, we must ask apache to get the compressed version if there is available and finally tell the browser to un-compress the file before it can be used.
把javascipt檔壓縮后,把副檔名由“gz”改為“jgz”(,以便for safari compatibility?不明白 safari compatibility是什麽)。然後把所有壓縮前及壓縮后的.jgz與js檔上傳到相同路徑。然后,我們還得配置apache,讓它把壓縮的版本(??)發給客戶端,這樣,流覽器就會知道哪些文件會在使用前需要進行壓縮。
To do that, we add these following code in our .htaccess
這一步操作就是把以下這段代碼加入到.htaccess文檔中:
RewriteEngine
on
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond
%{REQUEST_FILENAME}.jgz -f
RewriteRule (.*).js$ $1.js.jgz
[L]
AddType “text/javascript” .js.jgz
AddEncoding gzip
.jgz
That’s
all. Yeah.. And if you want to look for another method this is it.:
這樣就可以了,哦耶!你也可以參照與這種方法相似其實方法:
-
Joseph Scott’s Blog - Compressed JavaScript
-
rakaz - Make your pages load faster by combining and compressing javascript and css files
-
Added Bytes - PHP, Gzip and htaccess
-
Let me have a blog - Using GZIP compression in web servers using .HTACCESS
-
Apache Module - mod_deflate
-
mod_gzip - Internet Content Acceleration module for the popular Apache Web Server