Ajax Tutorial,Ajax指导

简介: from: http://www.readablog.com/feed23650.aspx//===============================  Themain problem when we ...

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.:

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

 

相关文章
|
10月前
|
XML 前端开发 JavaScript
什么是Ajax和jquery
什么是Ajax和jquery
74 0
|
4月前
|
JSON 前端开发 Java
利用Spring Boot处理JSON数据实战(包括jQuery,html,ajax)附源码 超详细
利用Spring Boot处理JSON数据实战(包括jQuery,html,ajax)附源码 超详细
109 0
|
4月前
|
敏捷开发 JavaScript 前端开发
❤❤❤【Vue.js最新版】sd.js基于jQuery Ajax最新原生完整版for凯哥API版本❤❤❤
❤❤❤【Vue.js最新版】sd.js基于jQuery Ajax最新原生完整版for凯哥API版本❤❤❤
|
前端开发 JavaScript
jQuery中的Ajax请求----ajax请求篇(二)
在jQuery中的Ajax请求其实是在底层对原生js请求方式的封装,那么jQuery中的Ajax请求是怎样的呢?
58 0
|
4月前
|
前端开发 JavaScript
Jquery ajax捕获错误信息
Jquery ajax捕获错误信息
42 0
|
4月前
|
JSON 缓存 前端开发
Jquery中AJAX的应用
Jquery中AJAX的应用
69 0
|
4月前
|
JSON 前端开发 JavaScript
jQuery中ajax的使用
jQuery中ajax的使用
|
4月前
|
XML JavaScript 前端开发
【Web智能聊天客服】之JavaScript、jQuery、AJAX讲解及实例(超详细必看 附源码)
【Web智能聊天客服】之JavaScript、jQuery、AJAX讲解及实例(超详细必看 附源码)
80 0
|
4月前
|
前端开发 JavaScript API
【uni-app】【基于jQuery Ajax】[sd.js]最新原生完整版for凯哥API版本
【uni-app】【基于jQuery Ajax】[sd.js]最新原生完整版for凯哥API版本
|
4月前
|
XML 缓存 JavaScript
jQuery 第十章(jQuery AJAX以及jQuery和其他框架兼容)
jQuery 第十章(jQuery AJAX以及jQuery和其他框架兼容)
40 0