UNPKG

1.6 kBMarkdownView Raw
1ajax-cache-parser
2=================
3
4[![NPM](https://nodei.co/npm/ajax-cache-parser.png?downloads=true&downloadRank=true)](https://nodei.co/npm/ajax-cache-parser/)
5
6[ ![Codeship Status for albertyw/ajax-cache-parser](https://codeship.com/projects/86d1e680-ba55-0133-baa7-025ac38368ea/status?branch=master)](https://codeship.com/projects/135666)
7[![Code Climate](https://codeclimate.com/github/albertyw/ajax-cache-parser/badges/gpa.svg)](https://codeclimate.com/github/albertyw/ajax-cache-parser)
8[![Test Coverage](https://codeclimate.com/github/albertyw/ajax-cache-parser/badges/coverage.svg)](https://codeclimate.com/github/albertyw/ajax-cache-parser/coverage)
9[![Dependency Status](https://gemnasium.com/albertyw/ajax-cache-parser.svg)](https://gemnasium.com/albertyw/ajax-cache-parser)
10
11A small function to get when an ajax request expires
12
13Given an XMLHttpRequest object that has received response headers back from a server, `getCacheExpiry` will return
14a javascript `Date` object that represents when the response will expire based on the `Expires` and `Cache-Control`
15response headers. If caching headers are not present or are unparseable, `undefined` will be returned. If caching
16headers indicate that the resource should not be cached, `null` will be returned.
17
18Example
19-------
20```javascript
21function callback(){
22 var expiration = parser.getCacheExpiry(this);
23 // do something with expiration
24}
25var oReq = new XMLHttpRequest();
26oReq.onload = callback;
27oReq.open("get", yourUrl, true);
28oReq.send();
29```
30
31Information about caching headers comes from: https://www.mnot.net/cache_docs/