From 2b40551efb4addaa227f8ad4b3af9b937a475bf1 Mon Sep 17 00:00:00 2001 From: Dorell James Galang Date: Wed, 3 Jul 2019 00:03:04 +0800 Subject: [PATCH] Add guide for Gatsby.js Caching (#31534) --- .../gatsbyjs/gatsbyjs-caching/index.md | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 guide/english/gatsbyjs/gatsbyjs-caching/index.md diff --git a/guide/english/gatsbyjs/gatsbyjs-caching/index.md b/guide/english/gatsbyjs/gatsbyjs-caching/index.md new file mode 100644 index 0000000000..13b0795f88 --- /dev/null +++ b/guide/english/gatsbyjs/gatsbyjs-caching/index.md @@ -0,0 +1,22 @@ +--- +title: Gatsby.js Caching +--- + +## Gatsby.js Caching Static Sites + +An important part of creating a very fast website is setting up proper HTTP caching. HTTP caching allows browsers to cache resources from a website so that when the user returns to a site, very few parts of the website have to be downloaded. Gatsby does this job automatically for you through Webpack. + +HTML files should never be cached while all files in `public/static/` should be cached forever. Also, other files e.g. JavaScript files should also be cached forever. + +## Cache Controls Headers + +HTML - The `cache-control` header should be `cache-control: public, max-age=0, must-revalidate` +Static Files (`/public/static`) - The `cache-control` header should be `cache-control: public,max-age=31536000,immutable` +JavaScript - The `cache-control` header should be `cache-control: public, max-age=31536000,immutable` + +## Plugins + +[Gatsby Plugin Netlify](https://www.gatsbyjs.org/packages/gatsby-plugin-netlify/) was created for automating caching when hosting your site at [Netlify](www.netlify.com). + +### More Information: +Check out the Gatsby.js official docs for caching at [Gatsby Caching](https://www.gatsbyjs.org/docs/caching). For more information and learn more, visit: [Gatsby.js official site](https://www.gatsbyjs.org/tutorial/)