UNPKG

1.56 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[![Build Status](https://drone.albertyw.com/api/badges/albertyw/ajax-cache-parser/status.svg)](https://drone.albertyw.com/albertyw/ajax-cache-parser)
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[![install size](https://packagephobia.com/badge?p=ajax-cache-parser)](https://packagephobia.com/result?p=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/