https://github.com/albertyw/ajax-cache-parser
A small function to calculate when an ajax request expires
https://github.com/albertyw/ajax-cache-parser
browser cache javascript
Last synced: 4 months ago
JSON representation
A small function to calculate when an ajax request expires
- Host: GitHub
- URL: https://github.com/albertyw/ajax-cache-parser
- Owner: albertyw
- License: mit
- Created: 2015-11-01T01:45:20.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-12-23T18:28:32.000Z (7 months ago)
- Last Synced: 2025-03-18T18:01:26.231Z (4 months ago)
- Topics: browser, cache, javascript
- Language: JavaScript
- Homepage:
- Size: 265 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
ajax-cache-parser
=================[](https://nodei.co/npm/ajax-cache-parser/)
[](https://drone.albertyw.com/albertyw/ajax-cache-parser)
[](https://codeclimate.com/github/albertyw/ajax-cache-parser)
[](https://codeclimate.com/github/albertyw/ajax-cache-parser/coverage)
[](https://packagephobia.com/result?p=ajax-cache-parser)A small function to get when an ajax request expires
Given an XMLHttpRequest object that has received response headers back from a server, `getCacheExpiry` will return
a javascript `Date` object that represents when the response will expire based on the `Expires` and `Cache-Control`
response headers. If caching headers are not present or are unparseable, `undefined` will be returned. If caching
headers indicate that the resource should not be cached, `null` will be returned.Example
-------
```javascript
function callback(){
var expiration = parser.getCacheExpiry(this);
// do something with expiration
}
var oReq = new XMLHttpRequest();
oReq.onload = callback;
oReq.open("get", yourUrl, true);
oReq.send();
```Information about caching headers comes from: https://www.mnot.net/cache_docs/