Skip to content

Commit 0167e60

Browse files
committed
feat!: remove cache headers
1 parent 0a90c2d commit 0167e60

File tree

4 files changed

+8
-126
lines changed

4 files changed

+8
-126
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ plugins: [
3131
allPageHeaders: [], // option to add headers for all pages. `Link` headers are transformed by the below criteria
3232
mergeSecurityHeaders: true, // boolean to turn off the default security headers
3333
mergeLinkHeaders: true, // boolean to turn off the default gatsby js headers
34-
mergeCachingHeaders: true, // boolean to turn off the default caching headers
3534
transformHeaders: (headers, path) => headers, // optional transform for manipulating headers under each path (e.g.sorting), etc.
3635
generateMatchPathRewrites: true, // boolean to turn off automatic creation of redirect rules for client only paths
3736
},

src/__tests__/__snapshots__/build-headers-program.js.snap

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,6 @@ exports[`build-headers-program with caching headers 1`] = `
88
X-XSS-Protection: 1; mode=block
99
X-Content-Type-Options: nosniff
1010
Referrer-Policy: same-origin
11-
/component---node-modules-gatsby-plugin-offline-app-shell-js-78f9e4dea04737fa062d.js
12-
Cache-Control: public, max-age=31536000, immutable
13-
/0-0180cd94ef2497ac7db8.js
14-
Cache-Control: public, max-age=31536000, immutable
15-
/component---src-templates-blog-post-js-517987eae96e75cddbe7.js
16-
Cache-Control: public, max-age=31536000, immutable
17-
/component---src-pages-404-js-53e6c51a5a7e73090f50.js
18-
Cache-Control: public, max-age=31536000, immutable
19-
/component---src-pages-index-js-0bdd01c77ee09ef0224c.js
20-
Cache-Control: public, max-age=31536000, immutable
21-
/webpack-runtime-acaa8994f1f704475e21.js
22-
Cache-Control: public, max-age=31536000, immutable
23-
/styles.1025963f4f2ec7abbad4.css
24-
Cache-Control: public, max-age=31536000, immutable
25-
/styles-565f081c8374bbda155f.js
26-
Cache-Control: public, max-age=31536000, immutable
27-
/app-f33c13590352da20930f.js
28-
Cache-Control: public, max-age=31536000, immutable
29-
/static/*
30-
Cache-Control: public, max-age=31536000, immutable
31-
/sw.js
32-
Cache-Control: no-cache
3311
/offline-plugin-app-shell-fallback/
3412
Link: </webpack-runtime-acaa8994f1f704475e21.js>; rel=preload; as=script
3513
Link: </styles-565f081c8374bbda155f.js>; rel=preload; as=script
@@ -96,30 +74,6 @@ exports[`build-headers-program with manifest['pages-manifest'] 1`] = `
9674
X-XSS-Protection: 1; mode=block
9775
X-Content-Type-Options: nosniff
9876
Referrer-Policy: same-origin
99-
/component---node-modules-gatsby-plugin-offline-app-shell-js-78f9e4dea04737fa062d.js
100-
Cache-Control: public, max-age=31536000, immutable
101-
/0-0180cd94ef2497ac7db8.js
102-
Cache-Control: public, max-age=31536000, immutable
103-
/component---src-templates-blog-post-js-517987eae96e75cddbe7.js
104-
Cache-Control: public, max-age=31536000, immutable
105-
/component---src-pages-404-js-53e6c51a5a7e73090f50.js
106-
Cache-Control: public, max-age=31536000, immutable
107-
/component---src-pages-index-js-0bdd01c77ee09ef0224c.js
108-
Cache-Control: public, max-age=31536000, immutable
109-
/pages-manifest-ab11f09e0ca7ecd3b43e.js
110-
Cache-Control: public, max-age=31536000, immutable
111-
/webpack-runtime-acaa8994f1f704475e21.js
112-
Cache-Control: public, max-age=31536000, immutable
113-
/styles.1025963f4f2ec7abbad4.css
114-
Cache-Control: public, max-age=31536000, immutable
115-
/styles-565f081c8374bbda155f.js
116-
Cache-Control: public, max-age=31536000, immutable
117-
/app-f33c13590352da20930f.js
118-
Cache-Control: public, max-age=31536000, immutable
119-
/static/*
120-
Cache-Control: public, max-age=31536000, immutable
121-
/sw.js
122-
Cache-Control: no-cache
12377
/offline-plugin-app-shell-fallback/
12478
Link: </webpack-runtime-acaa8994f1f704475e21.js>; rel=preload; as=script
12579
Link: </styles-565f081c8374bbda155f.js>; rel=preload; as=script
@@ -175,28 +129,6 @@ exports[`build-headers-program with security headers 1`] = `
175129
Content-Security-Policy: frame-ancestors 'self' https://*.storyblok.com/
176130
/hello
177131
X-Frame-Options: SAMEORIGIN
178-
/component---node-modules-gatsby-plugin-offline-app-shell-js-78f9e4dea04737fa062d.js
179-
Cache-Control: public, max-age=31536000, immutable
180-
/0-0180cd94ef2497ac7db8.js
181-
Cache-Control: public, max-age=31536000, immutable
182-
/component---src-templates-blog-post-js-517987eae96e75cddbe7.js
183-
Cache-Control: public, max-age=31536000, immutable
184-
/component---src-pages-404-js-53e6c51a5a7e73090f50.js
185-
Cache-Control: public, max-age=31536000, immutable
186-
/component---src-pages-index-js-0bdd01c77ee09ef0224c.js
187-
Cache-Control: public, max-age=31536000, immutable
188-
/webpack-runtime-acaa8994f1f704475e21.js
189-
Cache-Control: public, max-age=31536000, immutable
190-
/styles.1025963f4f2ec7abbad4.css
191-
Cache-Control: public, max-age=31536000, immutable
192-
/styles-565f081c8374bbda155f.js
193-
Cache-Control: public, max-age=31536000, immutable
194-
/app-f33c13590352da20930f.js
195-
Cache-Control: public, max-age=31536000, immutable
196-
/static/*
197-
Cache-Control: public, max-age=31536000, immutable
198-
/sw.js
199-
Cache-Control: no-cache
200132
/offline-plugin-app-shell-fallback/
201133
Link: </webpack-runtime-acaa8994f1f704475e21.js>; rel=preload; as=script
202134
Link: </styles-565f081c8374bbda155f.js>; rel=preload; as=script

src/build-headers-program.js

Lines changed: 8 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ import _ from "lodash"
22
import { writeFile, existsSync } from "fs-extra"
33
import { parse, posix } from "path"
44
import kebabHash from "kebab-hash"
5-
import { HEADER_COMMENT, IMMUTABLE_CACHING_HEADER } from "./constants"
5+
import { HEADER_COMMENT } from "./constants"
66

77
import {
88
COMMON_BUNDLES,
99
SECURITY_HEADERS,
10-
CACHING_HEADERS,
1110
LINK_REGEX,
1211
NETLIFY_HEADERS_FILENAME,
1312
PAGE_DATA_DIR,
@@ -219,16 +218,14 @@ const validateUserOptions = (pluginOptions, reporter) => headers => {
219218
)
220219
}
221220

222-
;[`mergeSecurityHeaders`, `mergeLinkHeaders`, `mergeCachingHeaders`].forEach(
223-
mergeOption => {
224-
if (!_.isBoolean(pluginOptions[mergeOption])) {
225-
throw new Error(
226-
`The "${mergeOption}" option to gatsby-plugin-netlify must be a boolean. ` +
227-
`Check your gatsby-config.js.`
228-
)
229-
}
221+
;[`mergeSecurityHeaders`, `mergeLinkHeaders`].forEach(mergeOption => {
222+
if (!_.isBoolean(pluginOptions[mergeOption])) {
223+
throw new Error(
224+
`The "${mergeOption}" option to gatsby-plugin-netlify must be a boolean. ` +
225+
`Check your gatsby-config.js.`
226+
)
230227
}
231-
)
228+
})
232229

233230
if (!_.isFunction(pluginOptions.transformHeaders)) {
234231
throw new Error(
@@ -299,44 +296,6 @@ const applySecurityHeaders =
299296
return headersMerge(headers, SECURITY_HEADERS)
300297
}
301298

302-
const applyCachingHeaders =
303-
(pluginData, { mergeCachingHeaders }) =>
304-
headers => {
305-
if (!mergeCachingHeaders) {
306-
return headers
307-
}
308-
309-
let chunks = []
310-
// Gatsby v3.5 added componentChunkName to store().components
311-
// So we prefer to pull chunk names off that as it gets very expensive to loop
312-
// over large numbers of pages.
313-
const isComponentChunkSet = !!pluginData.components.entries()?.next()
314-
?.value[1]?.componentChunkName
315-
if (isComponentChunkSet) {
316-
chunks = [...pluginData.components.values()].map(
317-
c => c.componentChunkName
318-
)
319-
} else {
320-
chunks = Array.from(pluginData.pages.values()).map(
321-
page => page.componentChunkName
322-
)
323-
}
324-
325-
chunks.push(`pages-manifest`, `app`)
326-
327-
const files = [].concat(...chunks.map(chunk => pluginData.manifest[chunk]))
328-
329-
const cachingHeaders = {}
330-
331-
files.forEach(file => {
332-
if (typeof file === `string`) {
333-
cachingHeaders[`/` + file] = [IMMUTABLE_CACHING_HEADER]
334-
}
335-
})
336-
337-
return defaultMerge(headers, cachingHeaders, CACHING_HEADERS)
338-
}
339-
340299
const applyTransfromHeaders =
341300
({ transformHeaders }) =>
342301
headers =>
@@ -359,7 +318,6 @@ export default function buildHeadersProgram(
359318
validateUserOptions(pluginOptions, reporter),
360319
mapUserLinkHeaders(pluginData),
361320
applySecurityHeaders(pluginOptions),
362-
applyCachingHeaders(pluginData, pluginOptions),
363321
mapUserLinkAllPageHeaders(pluginData, pluginOptions),
364322
applyLinkHeaders(pluginData, pluginOptions),
365323
applyTransfromHeaders(pluginOptions),

src/constants.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@ export const SECURITY_HEADERS = {
2525
],
2626
}
2727

28-
export const IMMUTABLE_CACHING_HEADER = `Cache-Control: public, max-age=31536000, immutable`
29-
30-
export const CACHING_HEADERS = {
31-
"/static/*": [IMMUTABLE_CACHING_HEADER],
32-
"/sw.js": [`Cache-Control: no-cache`],
33-
}
34-
3528
export const LINK_REGEX = /^(Link: <\/)(.+)(>;.+)/
3629
export const ROOT_WILDCARD = `/*`
3730

0 commit comments

Comments
 (0)