Ajax Tutorial,Ajax指导

8 篇文章 0 订阅
3 篇文章 0 订阅

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大小。完整的PrototypeScriptaculous加起來更是達到了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?

這對仍然使用GPRS56kbps撥號上網的用戶來講,簡直就是夢魘。這將花去流覽器很多時間去下載甚至永遠都不會下載這些網站文檔,因為流覽器通常會不下載這樣大的文件。很不幸的是,其實解決這個問題是非常簡單的(說不幸,又說很簡單,呃……)。你知道嗎?我們可以把這些文件壓縮或者是減小到一半甚至一半以下!

There are several method to compress javascript and I think one of the most efficient method is using Gzip Compression.

在許多壓縮javascript的辦法當中,我最讓為效果最好的就是使用Gzip壓縮法了。

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是什麽)。然後把所有壓縮前及壓縮后的.jgzjs檔上傳到相同路徑。然后,我們還得配置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.:

這樣就可以了,哦耶!你也可以參照與這種方法相似其實方法:

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值