@quintype/framework 7.23.2-update-cache-headers.1 → 7.23.2-update-cache-headers.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/constants.js +1 -0
- package/package.json +1 -1
- package/server/handlers/cdn-caching.js +4 -9
- package/server/handlers/generate-service-worker.js +3 -1
- package/server/handlers/json-manifest-handlers.js +2 -1
- package/test/integration/isomorphic-data-load-test.js +2 -1
- package/test/integration/isomorphic-handler-test.js +0 -8
package/constants.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const STALE_IF_ERROR_CACHE_DURATION = 14400;
|
package/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const { cache } = require("ejs");
|
|
2
2
|
const _ = require("lodash");
|
|
3
|
+
const { STALE_IF_ERROR_CACHE_DURATION } = require("../../constants");
|
|
3
4
|
|
|
4
5
|
exports.addCacheHeadersToResult = function addCacheHeadersToResult({
|
|
5
6
|
res,
|
|
@@ -16,7 +17,6 @@ exports.addCacheHeadersToResult = function addCacheHeadersToResult({
|
|
|
16
17
|
if (cacheKeys) {
|
|
17
18
|
if (cacheKeys === "DO_NOT_CACHE") {
|
|
18
19
|
res.setHeader("Cache-Control", "private,no-cache,no-store,max-age=0");
|
|
19
|
-
cdnProviderVal === "akamai" && res.setHeader("Edge-Control", "private,no-cache,no-store,max-age=0");
|
|
20
20
|
res.setHeader("Vary", "Accept-Encoding");
|
|
21
21
|
res.setHeader(
|
|
22
22
|
"Content-Security-Policy",
|
|
@@ -34,19 +34,16 @@ exports.addCacheHeadersToResult = function addCacheHeadersToResult({
|
|
|
34
34
|
);
|
|
35
35
|
} else {
|
|
36
36
|
if (networkOnly) {
|
|
37
|
-
res.setHeader("Cache-Control", `public,s-maxage=${sMaxAge},stale-if-error
|
|
37
|
+
res.setHeader("Cache-Control", `public,s-maxage=${sMaxAge},stale-if-error=${STALE_IF_ERROR_CACHE_DURATION}`);
|
|
38
38
|
res.setHeader(
|
|
39
39
|
"Cloudflare-CDN-Cache-Control",
|
|
40
|
-
`max-age=${sMaxAge},stale-if-error
|
|
40
|
+
`max-age=${sMaxAge}, stale-while-revalidate=1000, stale-if-error=${STALE_IF_ERROR_CACHE_DURATION}`
|
|
41
41
|
);
|
|
42
|
-
cdnProviderVal === "akamai" && res.setHeader("Edge-Control", `public,maxage=${sMaxAge}`);
|
|
43
42
|
} else {
|
|
44
43
|
res.setHeader(
|
|
45
44
|
"Cache-Control",
|
|
46
|
-
`public,max-age=${maxAge},s-maxage=${sMaxAge},stale-while-revalidate=1000,stale-if-error
|
|
45
|
+
`public,max-age=${maxAge},s-maxage=${sMaxAge},stale-while-revalidate=1000,stale-if-error=${STALE_IF_ERROR_CACHE_DURATION}`
|
|
47
46
|
);
|
|
48
|
-
cdnProviderVal === "akamai" &&
|
|
49
|
-
res.setHeader("Edge-Control", `public,maxage=${sMaxAge},stale-while-revalidate=1000,stale-if-error=14400`);
|
|
50
47
|
}
|
|
51
48
|
|
|
52
49
|
res.setHeader("Vary", "Accept-Encoding");
|
|
@@ -75,8 +72,6 @@ exports.addCacheHeadersToResult = function addCacheHeadersToResult({
|
|
|
75
72
|
}
|
|
76
73
|
} else {
|
|
77
74
|
res.setHeader("Cache-Control", "public,max-age=15,s-maxage=60,stale-while-revalidate=150,stale-if-error=3600");
|
|
78
|
-
cdnProviderVal === "akamai" &&
|
|
79
|
-
res.setHeader("Edge-Control", "public,maxage=60,stale-while-revalidate=150,stale-if-error=3600");
|
|
80
75
|
res.setHeader("Vary", "Accept-Encoding");
|
|
81
76
|
res.setHeader(
|
|
82
77
|
"Content-Security-Policy",
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const { STALE_IF_ERROR_CACHE_DURATION } = require("../../constants");
|
|
2
|
+
|
|
1
3
|
async function generateServiceWorker(
|
|
2
4
|
req,
|
|
3
5
|
res,
|
|
@@ -39,7 +41,7 @@ async function generateServiceWorker(
|
|
|
39
41
|
res
|
|
40
42
|
.status(200)
|
|
41
43
|
.header("Content-Type", "application/javascript")
|
|
42
|
-
.header("Cache-Control",
|
|
44
|
+
.header("Cache-Control", `public,max-age=300, stale-while-revalidate=1000, stale-if-error=${STALE_IF_ERROR_CACHE_DURATION}`)
|
|
43
45
|
.header("Vary", "Accept-Encoding")
|
|
44
46
|
.header(
|
|
45
47
|
"Cache-Tag",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const get = require("lodash/get");
|
|
2
2
|
const Promise = require("bluebird");
|
|
3
|
+
const { STALE_IF_ERROR_CACHE_DURATION } = require("../../constants");
|
|
3
4
|
|
|
4
5
|
exports.handleManifest = function handleManifest(
|
|
5
6
|
req,
|
|
@@ -9,7 +10,7 @@ exports.handleManifest = function handleManifest(
|
|
|
9
10
|
) {
|
|
10
11
|
return new Promise((resolve) => resolve(manifestFn(config, domainSlug)))
|
|
11
12
|
.then((result) => {
|
|
12
|
-
res.setHeader("Cache-Control",
|
|
13
|
+
res.setHeader("Cache-Control", `public,max-age=900,stale-while-revalidate=1000, stale-if-error=${STALE_IF_ERROR_CACHE_DURATION}`);
|
|
13
14
|
res.setHeader("Vary", "Accept-Encoding");
|
|
14
15
|
res.json(
|
|
15
16
|
Object.assign(
|
|
@@ -7,6 +7,7 @@ const supertest = require("supertest");
|
|
|
7
7
|
const {
|
|
8
8
|
MOCK_WHITELIST_MOBILE_CONFIG,
|
|
9
9
|
} = require("../data/whitelist-mobile-config");
|
|
10
|
+
const { STALE_IF_ERROR_CACHE_DURATION } = require("../../constants");
|
|
10
11
|
|
|
11
12
|
function getClientStub() {
|
|
12
13
|
return {
|
|
@@ -158,7 +159,7 @@ describe("Isomorphic Data Load", function () {
|
|
|
158
159
|
.expect("Content-Type", /json/)
|
|
159
160
|
.expect(
|
|
160
161
|
"Cache-Control",
|
|
161
|
-
|
|
162
|
+
`public,s-maxage=900,stale-if-error=${STALE_IF_ERROR_CACHE_DURATION}`,
|
|
162
163
|
)
|
|
163
164
|
.expect("Vary", "Accept-Encoding")
|
|
164
165
|
.expect("Cache-Tag", "foo,bar")
|
|
@@ -559,12 +559,10 @@ describe("Isomorphic Handler", function () {
|
|
|
559
559
|
.expect(200)
|
|
560
560
|
.then((res) => {
|
|
561
561
|
const cacheControl = res.header["cache-control"];
|
|
562
|
-
const edgeCacheControl = res.header["edge-control"];
|
|
563
562
|
const cacheTag = res.header["cache-tag"];
|
|
564
563
|
const edgeCacheTag = res.header["edge-cache-tag"];
|
|
565
564
|
const contentSecurityPolicy = res.header["content-security-policy"];
|
|
566
565
|
assert.equal(cacheControl, "private,no-cache,no-store,max-age=0");
|
|
567
|
-
assert.equal(edgeCacheControl, "private,no-cache,no-store,max-age=0");
|
|
568
566
|
assert.equal(cacheTag, undefined);
|
|
569
567
|
assert.equal(edgeCacheTag, undefined);
|
|
570
568
|
assert.equal(
|
|
@@ -602,11 +600,9 @@ describe("Isomorphic Handler", function () {
|
|
|
602
600
|
.expect(200)
|
|
603
601
|
.then((res) => {
|
|
604
602
|
const cacheControl = res.header["cache-control"];
|
|
605
|
-
const edgeCacheControl = res.header["edge-control"];
|
|
606
603
|
const edgeCacheTag = res.header["edge-cache-tag"];
|
|
607
604
|
const contentSecurityPolicy = res.header["content-security-policy"];
|
|
608
605
|
assert.equal(cacheControl, "public,max-age=15,s-maxage=60,stale-while-revalidate=150,stale-if-error=3600");
|
|
609
|
-
assert.equal(edgeCacheControl, "public,maxage=60,stale-while-revalidate=150,stale-if-error=3600");
|
|
610
606
|
assert.equal(edgeCacheTag, undefined);
|
|
611
607
|
assert.equal(
|
|
612
608
|
contentSecurityPolicy,
|
|
@@ -643,11 +639,9 @@ describe("Isomorphic Handler", function () {
|
|
|
643
639
|
.expect(200)
|
|
644
640
|
.then((res) => {
|
|
645
641
|
const cacheControl = res.header["cache-control"];
|
|
646
|
-
const edgeCacheControl = res.header["edge-control"];
|
|
647
642
|
const edgeCacheTag = res.header["edge-cache-tag"];
|
|
648
643
|
const contentSecurityPolicy = res.header["content-security-policy"];
|
|
649
644
|
assert.equal(cacheControl, "public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400");
|
|
650
|
-
assert.equal(edgeCacheControl, "public,maxage=900,stale-while-revalidate=1000,stale-if-error=14400");
|
|
651
645
|
assert.equal(edgeCacheTag, "c/1/abcdefgh");
|
|
652
646
|
assert.equal(
|
|
653
647
|
contentSecurityPolicy,
|
|
@@ -684,11 +678,9 @@ describe("Isomorphic Handler", function () {
|
|
|
684
678
|
.expect(200)
|
|
685
679
|
.then((res) => {
|
|
686
680
|
const cacheControl = res.header["cache-control"];
|
|
687
|
-
const edgeCacheControl = res.header["edge-control"];
|
|
688
681
|
const edgeCacheTag = res.header["edge-cache-tag"];
|
|
689
682
|
const contentSecurityPolicy = res.header["content-security-policy"];
|
|
690
683
|
assert.equal(cacheControl, "public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400");
|
|
691
|
-
assert.equal(edgeCacheControl, "public,maxage=900,stale-while-revalidate=1000,stale-if-error=14400");
|
|
692
684
|
assert.equal(edgeCacheTag, "c/1/abcdefgh");
|
|
693
685
|
assert.equal(
|
|
694
686
|
contentSecurityPolicy,
|