You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Gatsby has an Image CDN feature which speeds up your build times as well as your frontend performance.
46
+
47
+
Previously Gatsby would fetch all image files during the Gatsby build process, transform them for frontend performance, and then serve them as static files on the frontend.
48
+
With the new Image CDN feature images are lazily processed when users visit the frontend of your site. The first front-end visitor of any image will transform that image and cache it for all other users.
49
+
Note that Image CDN works on all hosting platforms, but only speeds up your builds on Gatsby Cloud, as Gatsby Cloud is the most advanced CI/CD and hosting platform for the Gatsby framework.
50
+
51
+
-[Image CDN blog post](https://www.gatsbyjs.com/blog/image-cdn-lightning-fast-image-processing-for-gatsby-cloud/)
52
+
-[What is Image CDN?](https://support.gatsbyjs.com/hc/en-us/articles/4426379634835-What-is-Image-CDN-)
53
+
-[How to enable Image CDN on Gatsby Cloud](https://support.gatsbyjs.com/hc/en-us/articles/4426393233171-How-to-Enable-Image-CDN)
54
+
55
+
#### Querying for Gatsby Image CDN fields
56
+
57
+
Follow [this guide](https://support.gatsbyjs.com/hc/en-us/articles/4426393233171-How-to-Enable-Image-CDN) to understand how to use the new `gatsbyImage` GraphQL field.
58
+
59
+
#### Turning off file downloads
60
+
61
+
When you're using Gatsby Image CDN you no longer need Gatsby to fetch all of the files in your Drupal instance. Turn that off with the following plugin option. This is required for Image CDN to work.
62
+
63
+
```js
64
+
{
65
+
resolve:`gatsby-source-drupal`,
66
+
options: {
67
+
skipFileDownloads:true,
68
+
// other plugin options go here
69
+
},
70
+
},
71
+
```
72
+
73
+
#### Local dev improvements
74
+
75
+
Using Image CDN also speeds up your local development startup times when running `gatsby develop`. Instead of fetching all files locally, `gatsby develop` has a local Image CDN emulator.
76
+
This means Gatsby will only fetch and process the minimal amount of images required to render any page when you visit your Gatsby site at `http://localhost:8000`.
77
+
78
+
#### Configuring placeholders for Gatsby Images
79
+
80
+
By default full size images are fetched and scaled down to be used for low quality image placeholders (for lazy loading images on the frontend).
81
+
This can make your builds slower than necessary so follow these steps to configure a new smaller placeholder image size in Drupal. This will speed up your builds when using Gatsby Image CDN.
82
+
83
+
1. Install the [Consumer image styles module](https://www.drupal.org/project/consumer_image_styles)
84
+
2. Navigate to "Extend->Web Services" and turn on "Consumer Image Styles" by checking the box and hitting save.
85
+
3. Navigate to "Configuration->Image Styles". and add an image style called "Placeholder".
86
+
4. Create a new scale effect and set its width and height to 20.
87
+
5. If you already have a placeholder style you want to use, you can set the `gatsby-source-drupal` plugin option `placeholderStyleName` as the machine name of your style. \*\* See example option below
88
+
6. For each entity that has an image field, navigate into "Configuration->Web Services->JSON:API->JSON:API Resource Overrides->Entity Type->(overwrite/edit)".
89
+
7. Click on "advanced" for each image field you have, select "Image Styles (Image Field)" in the dropdown, then select the placeholder image style and save.
90
+
8. Go to "Configuration->Web Services->Consumers" and add a default consumer if it doesn't already exist.
91
+
9. Edit your default consumer and add the "Placeholder" image style by checking the box in the bottom section and saving.
92
+
10. You may need to clear Drupal's cache under "Config->development->clear all caches".
93
+
94
+
\*\* Example placeholder style plugin option
95
+
96
+
```js
97
+
{
98
+
resolve:`gatsby-source-drupal`,
99
+
options: {
100
+
placeholderStyleName:`custom_placeholder`// default is `placeholder`
101
+
}
102
+
}
103
+
```
104
+
43
105
### Filters
44
106
45
107
You can use the `filters` option to limit the data that is retrieved from Drupal. Filters are applied per JSON API collection. You can use any [valid JSON API filter query](https://www.drupal.org/docs/8/modules/jsonapi/filtering). For large data sets this can reduce the build time of your application by allowing Gatsby to skip content you'll never use.
`[gatsby-source-drupal]\nNo Gatsby Image CDN placeholder style found. Please ensure that you have a placeholder style in your Drupal site for the fastest builds. See the docs for more info on gatsby-source-drupal Image CDN support:\n\nhttps://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-source-drupal#readme`
// polyfill so image CDN works on older versions of Gatsby
862
+
addRemoteFilePolyfillInterface(
863
+
// this type is merged in with the inferred file__file type, adding Image CDN support via the gatsbyImage GraphQL field. The `RemoteFile` interface as well as the polyfill above are what add the gatsbyImage field.
0 commit comments