1 | ajax-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 |
|
11 | A small function to get when an ajax request expires
|
12 |
|
13 | Given an XMLHttpRequest object that has received response headers back from a server, `getCacheExpiry` will return
|
14 | a javascript `Date` object that represents when the response will expire based on the `Expires` and `Cache-Control`
|
15 | response headers. If caching headers are not present or are unparseable, `undefined` will be returned. If caching
|
16 | headers indicate that the resource should not be cached, `null` will be returned.
|
17 |
|
18 | Example
|
19 | -------
|
20 | ```javascript
|
21 | function callback(){
|
22 | var expiration = parser.getCacheExpiry(this);
|
23 | // do something with expiration
|
24 | }
|
25 | var oReq = new XMLHttpRequest();
|
26 | oReq.onload = callback;
|
27 | oReq.open("get", yourUrl, true);
|
28 | oReq.send();
|
29 | ```
|
30 |
|
31 | Information about caching headers comes from: https://www.mnot.net/cache_docs/
|