?? cache.js
字號:
/* Copyright 2006 Christian Gross http://www.devspace.com From the book Ajax Patterns and Best Practices Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.*/var CacheController = { _cache : new Array(), prefetch : function( url) { }, didNotFindETagError : function( url) { }, getCachedURL : function( url) { var func = function( status, statusText, responseText, responseXML) { } CacheController.getURL( url, func, true); }, getURL : function( url, complete, calledFromCache) { var asynchronous = new Asynchronous(); asynchronous.openCallback = function( xmlhttp) { var obj = CacheController._cache[ url]; if( obj != null) { xmlhttp.setRequestHeader( "If-None-Match", obj.ETag); } } asynchronous.userComplete = complete; asynchronous.complete = function( status, statusText, responseText, responseXML) { if( status == 200) { try { var foundetag = this._xmlhttp.getResponseHeader( "ETag"); if( foundetag != null) { CacheController._cache[ url] = { ETag : foundetag, Status : status, StatusText : statusText, ResponseText : responseText, ResponseXML : responseXML }; } else { CacheController.didNotFindETagError( url); } } catch( exception) { CacheController.didNotFindETagError( url); } this.userComplete( status, statusText, responseText, responseXML); } else if( status == 304) { var obj = CacheController._cache[ url]; if( obj != null) { this.userComplete( 304, obj.StatusText, obj.ResponseText, obj.ResponseXML); } else { throw new Error( "Server indicated that this data is in the cache, but it does not seem to be"); } } else { this.userComplete( status, statusText, responseText, responseXML); } } asynchronous.get( url); if( calledFromCache != true) { CacheController.prefetch( url); } }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -