├── .gitignore
├── lib
├── fetch_util.js
├── url_util.js
├── delta_cache_sw.js
├── fetch_proxy.js
└── delta_fetch.js
├── test
├── public
│ ├── test.html
│ ├── mocha_driver.js
│ ├── test.js
│ ├── delta_cache_sw.min.js
│ └── delta_cache_sw.js
└── test.js
├── demo
├── public
│ ├── style.css
│ ├── demo.html
│ ├── demo.js
│ └── delta_cache_sw.js
└── server.js
├── gulpfile.js
├── package.json
├── README.md
└── dist
├── delta_cache_sw.min.js
└── delta_cache_sw.js
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea
2 | node_modules
3 | npm-debug.log*
4 |
--------------------------------------------------------------------------------
/lib/fetch_util.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | // copies all headers into a new Headers
4 | function cloneHeaders(headers) {
5 | let headersClone = new Headers();
6 | for (let [name, value] of headers.entries()) {
7 | headersClone.append(name, value);
8 | }
9 | return headersClone;
10 | }
11 |
12 | function printHeaders(headers) {
13 | for (let [name, value] of headers.entries()) {
14 | console.log(name + ': ' + value);
15 | }
16 | }
17 |
18 |
19 | module.exports = {
20 | cloneHeaders,
21 | printHeaders
22 | };
23 |
--------------------------------------------------------------------------------
/test/public/test.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
17 |
Delta Cache Demo
18 |
19 |
Code
20 |
21 |
Fetch dynamic content
22 |
23 |
Fetch dynamic content with delta encoding
24 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/test/test.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const http = require('http');
4 | const fs = require('fs');
5 |
6 | const express = require('express');
7 | const createDeltaCache = require('delta-cache');
8 | const open = require('open');
9 |
10 | const deltaCache = createDeltaCache();
11 |
12 | const app = express();
13 | app.use(express.static('test/public'));
14 |
15 | let first = true;
16 | app.get('/dynamicContent', (req, res) => {
17 | console.log('GET', req.url);
18 | if (first) {
19 | res.locals.responseBody = 'version 1';
20 | first = false;
21 | console.log(res.locals.responseBody);
22 | deltaCache.respondWithDeltaEncoding(req, res, res.locals.responseBody);
23 | }
24 | else {
25 | res.locals.responseBody = 'version 2';
26 | console.log(res.locals.responseBody);
27 | deltaCache.respondWithDeltaEncoding(req, res, res.locals.responseBody, () => {
28 | process.exit()
29 | });
30 | }
31 | });
32 |
33 | app.get('/staticContent', (req, res) => {
34 | res.locals.responseBody = 'single response';
35 | console.log('GET', req.url);
36 | console.log(res.locals.responseBody);
37 | deltaCache.respondWithDeltaEncoding(req, res, res.locals.responseBody);
38 | });
39 |
40 | app.get('/noDelta', (req, res) => {
41 | console.log('GET', req.url);
42 | console.log('single response');
43 | res.send('single response');
44 | });
45 |
46 | app.listen(8080, (err) => {
47 | open('http://localhost:8080/test.html');
48 | });
49 |
--------------------------------------------------------------------------------
/demo/public/demo.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | $(function() {
4 | const log = str => $('#log-box').append(str).append('