Skip to content

Commit 0a7b223

Browse files
fix: update image CDN docs and defaults (#307)
* chore: default image CDN to disabled * chore: update docs Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent bb51c53 commit 0a7b223

File tree

4 files changed

+56
-50
lines changed

4 files changed

+56
-50
lines changed

README.md

Lines changed: 4 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -80,53 +80,10 @@ Gatsby Functions or the remote image CDN.
8080

8181
### Gatsby Image CDN
8282

83-
Gatsby 5 includes beta support for deferred image resizing using a CDN. This can
84-
greatly improve build times for sites with remote images, such as those that use
85-
a CMS. When using these, images do not need to be downloaded and resized at
86-
build time, and instead are built on the fly when first loaded. The image CDN is
87-
enabled by default on Netlify, but can be disabled by setting the environment
88-
variable `GATSBY_CLOUD_IMAGE_CDN` to `false`.
89-
90-
When using the image CDN, Gatsby generates URLs of the form
91-
`/_gatsby/image/...`. On Netlify, these are served by a
92-
[builder function](https://docs.netlify.com/configure-builds/on-demand-builders/),
93-
powered by [sharp](https://sharp.pixelplumbing.com/) and Nuxt's
94-
[ipx image server](https://github.com/unjs/ipx/). It supports all image formats
95-
supported by Gatsby, including AVIF and WebP.
96-
97-
On first load there will be a one-time delay while the image is resized, but
98-
subsequent requests will be super-fast as they are served from the cache.
99-
100-
Currently Gatsby supports the image CDN for sites that use Contentful or
101-
WordPress, but more should be added and will be enabled automatically when
102-
available in the plugin.
103-
104-
When using WordPress with the image CDN, we recommend disabling downloading of
105-
files if possible by setting
106-
[`createFileNodes`](https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-source-wordpress/docs/plugin-options.md#typemediaitemcreatefilenodes)
107-
to `false`. You should also setup an image size in WordPress to use as a
108-
placeholder. See
109-
[the `gatsby-source-wordpress` docs](https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-source-wordpress/docs/plugin-options.md#typemediaitemplaceholdersizename)
110-
for more details.
111-
112-
For example:
113-
114-
```js
115-
module.exports = {
116-
plugins: [
117-
{
118-
resolve: `gatsby-source-wordpress`,
119-
options: {
120-
url: 'https://example.com/graphql',
121-
type: { MediaItem: { createFileNodes: false } },
122-
},
123-
},
124-
],
125-
}
126-
```
127-
128-
For more information about Gatsby's image CDN feature, see
129-
[the Gatsby docs](https://gatsby.dev/img).
83+
Gatsby includes beta support for deferred image resizing using a CDN. Netlify
84+
includes full support for Image CDN on all plans. For details on how to enable
85+
it, see
86+
[the image CDN docs](https://github.com/netlify/netlify-plugin-gatsby/blob/main/docs/image-cdn.md).
13087

13188
### Caveats
13289

docs/image-cdn.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Gatsby Image CDN on Netlify
2+
3+
Gatsby Image CDN is a new feature available in the prerelease version of Gatsby.
4+
Instead of downloading and processing images at build time, it defers processing
5+
until request time. This can greatly improve build times for sites with remote
6+
images, such as those that use a CMS. Netlify includes full support for Image
7+
CDN, on all plans.
8+
9+
When using the image CDN, Gatsby generates URLs of the form
10+
`/_gatsby/image/...`. On Netlify, these are served by a
11+
[builder function](https://docs.netlify.com/configure-builds/on-demand-builders/),
12+
powered by [sharp](https://sharp.pixelplumbing.com/) and Nuxt's
13+
[ipx image server](https://github.com/unjs/ipx/). It supports all image formats
14+
supported by Gatsby, including AVIF and WebP.
15+
16+
On first load there will be a one-time delay while the image is resized, but
17+
subsequent requests will be super-fast as they are served from the edge cache.
18+
19+
## Enabling the Image CDN
20+
21+
To enable the Image CDN during the beta period, you should set the environment
22+
variable `GATSBY_CLOUD_IMAGE_CDN` to `true`.
23+
24+
Image CDN currently requires the beta version of Gatsby. This can be installed
25+
using the `next` tag:
26+
27+
```shell
28+
npm install gatsby@next gatsby-plugin-image@next gatsby-plugin-sharp@next gatsby-transformer-sharp@next
29+
```
30+
31+
Currently Image CDN supports Contentful and WordPress, and these source plugins
32+
should also be installed using the `next` tag:
33+
34+
```shell
35+
npm install gatsby-source-wordpress@next
36+
```
37+
38+
or
39+
40+
```shell
41+
npm install gatsby-source-contentful@next
42+
```
43+
44+
Gatsby will be adding support to more source plugins during the beta period.
45+
These should work automatically as soon as they are added.
46+
47+
## Using the Image CDN
48+
49+
Your GraphQL queries will need updating to use the image CDN. The details vary
50+
depending on the source plugin. For more details see
51+
[the Gatsby docs](https://support.gatsbyjs.com/hc/en-us/articles/4522338898579)

plugin/src/helpers/functions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export const setupImageCdn = async ({
6969
}) => {
7070
const { GATSBY_CLOUD_IMAGE_CDN } = netlifyConfig.build.environment
7171

72-
if (GATSBY_CLOUD_IMAGE_CDN === '0' || GATSBY_CLOUD_IMAGE_CDN === 'false') {
72+
if (GATSBY_CLOUD_IMAGE_CDN !== '1' && GATSBY_CLOUD_IMAGE_CDN !== 'true') {
7373
return
7474
}
7575

plugin/src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ export async function onPreBuild({
3333
await restoreCache({ utils, publish: PUBLISH_DIR })
3434

3535
checkGatsbyConfig({ utils, netlifyConfig })
36-
// eslint-disable-next-line no-param-reassign
37-
netlifyConfig.build.environment.GATSBY_CLOUD_IMAGE_CDN ||= '1'
3836
}
3937

4038
export async function onBuild({

0 commit comments

Comments
 (0)