Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b655680

Browse files
committedJun 11, 2021
set correct cache headers for all files under static/
1 parent 76942ff commit b655680

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed
 

‎firebase.json

+51-1
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,62 @@
77
},
88
"hosting": {
99
"public": "public",
10-
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
10+
"ignore": ["**/.*", "**/node_modules/**"],
1111
"rewrites": [
1212
{
1313
"source": "**",
1414
"destination": "/index.html"
1515
}
16+
],
17+
"headers": [
18+
// Set up cache headers based on:
19+
//
20+
// https://www.gatsbyjs.com/docs/how-to/previews-deploys-hosting/deploying-to-firebase/
21+
{
22+
"source": "**/*",
23+
"headers": [
24+
{
25+
"key": "cache-control",
26+
"value": "public, max-age=0, must-revalidate"
27+
}
28+
]
29+
},
30+
{
31+
"source": "static/**",
32+
"headers": [
33+
{
34+
"key": "cache-control",
35+
"value": "public, max-age=31536000, immutable"
36+
}
37+
]
38+
},
39+
{
40+
"source": "**/*.@(css|js)",
41+
"headers": [
42+
{
43+
"key": "cache-control",
44+
"value": "public, max-age=31536000, immutable"
45+
}
46+
]
47+
},
48+
{
49+
"source": "sw.js",
50+
"headers": [
51+
{
52+
"key": "cache-control",
53+
"value": "public, max-age=0, must-revalidate"
54+
}
55+
]
56+
},
57+
{
58+
"source": "page-data/**",
59+
"headers": [
60+
{
61+
"key": "cache-control",
62+
"value": "public, max-age=0, must-revalidate"
63+
}
64+
]
65+
}
1666
]
1767
}
1868
}

‎gatsby-node.js

+11
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414
const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin")
15+
const fs = require("fs")
1516

1617
require("ts-node").register({
1718
compilerOptions: {
@@ -30,3 +31,13 @@ exports.onCreateWebpackConfig = ({ actions }) => {
3031
},
3132
})
3233
}
34+
35+
// Copy the firebase.json file over to the public directory so things like
36+
// redirects can be handled at the server-level.
37+
exports.onPostBuild = () => {
38+
fs.copyFile(`./firebase.json`, `./public/firebase.json`, err => {
39+
if (err) {
40+
throw err
41+
}
42+
})
43+
}

0 commit comments

Comments
 (0)
Please sign in to comment.