Skip to content

Commit d821f0e

Browse files
thecodingaviatorDSchau
authored andcommitted
feat(gatsby-plugin-sharp): remove 3x DPi resolutions (#14201)
* Remove images having 3x dimensions of original * Make tests not include 3x image size checking * Remove all instances of 3x images and related code * Remove 3x sizing from gatsby-source-contentful/extend-node-type.js * Revert changes to gatsby-source-contentful * Revert changes to examples/using-contentful * five -> four to reflect one image size being removed * Update preoptimizing-images.md * Remove images having 3x dimensions of original * Make tests not include 3x image size checking * Remove all instances of 3x images and related code * Remove 3x sizing from gatsby-source-contentful/extend-node-type.js * Revert changes to gatsby-source-contentful * Revert changes to examples/using-contentful * five -> four to reflect one image size being removed * Update preoptimizing-images.md * Update e2e-tests/gatsby-image/cypress/integration/fixed.js Co-Authored-By: Dustin Schau <[email protected]> * test: add a negation test for the 3x srcset
1 parent 2870dfb commit d821f0e

File tree

6 files changed

+17
-15
lines changed

6 files changed

+17
-15
lines changed

docs/blog/2019-04-02-behind-the-scenes-what-makes-gatsby-great/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ There are far, far, far too many otherwise decently performing websites that loa
394394
- Responsive, optimized images using a `srcset`
395395
- A [`picture`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/picture) element with a `source srcset` is used
396396
- This means that using several media queries, you load the smallest image that matches your device (e.g. mobile devices get smaller images, desktop devices get larger images, etc.)
397-
- We even generate 2x and 3x DPi images for beautiful images, regardless of the screen quality!
397+
- We even generate 2x DPi images for beautiful images, regardless of the screen quality!
398398
- A base64 blurred image loaded by default
399399
- This has two wins: 1) Larger images outside the viewport are not requested until they're needed, and 2) The blurred image is in a container with the same dimensions as the real image--therefore, no jumping when the image loads!
400400
- Also see: [traced SVGs for a super slick alternative](/packages/gatsby-plugin-sharp/#tracedsvg)

docs/docs/preoptimizing-images.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ title: Preoptimizing your Images
44

55
Gatsby ships with excellent image optimization capabilities (see the [Image Tutorial](/tutorial/image-tutorial/) for more info). However, this image optimization can come with a cost. It can be fairly CPU intensive, and in some cases may lead to long build times. As a means of debugging and perhaps improving your overall build performance, it _may_ be helpful to pre-optimize your (extremely large) images.
66

7-
First, some context. `gatsby-plugin-sharp` ships with a `fluid` option which will attempt to create five images intended to map to various screen resolutions. Producing multiple images ensures that your images are ready and optimized for phone displays, desktop displays, and everything in between. This plugin receives a non-optimized image and produces optimized images for _all_ of your users and devices. Magic!
7+
First, some context. `gatsby-plugin-sharp` ships with a `fluid` option which will attempt to create four images intended to map to various screen resolutions. Producing multiple images ensures that your images are ready and optimized for phone displays, desktop displays, and everything in between. This plugin receives a non-optimized image and produces optimized images for _all_ of your users and devices. Magic!
88

99
If you find yourself running into build performance issues, it could be helpful to consider applying some image optimizations. Images in your setup _could_ be overly large, especially compared to the requested image sizes in your layout (e.g. if your layout has a max width of 600 pixels).
1010

11-
For instance, if your layout is 600 pixels wide, then the highest resolution image you will need is 1800 pixels to account for 3x pixel density. If you have images that are 3000 or 4000 pixels wide then you could resize your image to 1800 pixels, which may improve overall build performance.
11+
For instance, if your layout is 600 pixels wide, then the highest resolution image you will need is 1200 pixels to account for 2x pixel density. If you have images that are 3000 or 4000 pixels wide then you could resize your image to 1800 pixels, which may improve overall build performance.
1212

1313
Here's an example script to pre-optimize your image dimensions and slightly compress. This optimization may serve as a helpful technique to possibly improve build time if your local repository has many, very large images.
1414

e2e-tests/gatsby-image/cypress/integration/fixed.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,26 @@ describe(`fixed`, () => {
2222
})
2323
})
2424

25-
// TODO: figure out why these tests are failing
26-
it(`applies 1x/2x/3x`, () => {
25+
it(`applies 1x/2x`, () => {
2726
cy.getTestElement(fixedTestId)
2827
.find(`picture > source`)
2928
.should(`have.attr`, `srcset`)
3029
.and(srcset => {
31-
;[`1x`, `2x`, `3x`].forEach(size => {
30+
;[`1x`, `2x`].forEach(size => {
3231
expect(srcset).contains(size)
3332
})
3433
})
3534
})
3635

36+
it(`does not apply 3x`, () => {
37+
cy.getTestElement(fixedTestId)
38+
.find(`picture > source`)
39+
.should(`have.attr`, `srcset`)
40+
.and(srcset => {
41+
expect(srcset).not.contains(`3x`)
42+
})
43+
})
44+
3745
describe(`picture > img sizing`, () => {
3846
it(`applies height attribute`, () => {
3947
cy.getTestElement(fixedTestId)

examples/image-processing/src/pages/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ class Index extends React.Component {
316316
</p>
317317
<p>
318318
Automatically create images for different resolutions — we do 1x,
319-
1.5x, 2x, and 3x.
319+
1.5x, and 2x.
320320
{` `}
321321
</p>
322322

packages/gatsby-plugin-sharp/README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ plugins: [
6060

6161
### fixed
6262

63-
Automatically create sizes for different resolutions — we do 1x, 1.5x, 2x, and
64-
3x.
63+
Automatically create sizes for different resolutions — we do 1x, 1.5x, and 2x.
6564

6665
#### Parameters
6766

packages/gatsby-plugin-sharp/src/index.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,6 @@ async function fluid({ file, args = {}, reporter, cache }) {
316316
fluidSizes.push(options[fixedDimension] / 2)
317317
fluidSizes.push(options[fixedDimension] * 1.5)
318318
fluidSizes.push(options[fixedDimension] * 2)
319-
fluidSizes.push(options[fixedDimension] * 3)
320319
} else {
321320
options.srcSetBreakpoints.forEach(breakpoint => {
322321
if (breakpoint < 1) {
@@ -436,12 +435,11 @@ async function fixed({ file, args = {}, reporter, cache }) {
436435
// if no width is passed, we need to resize the image based on the passed height
437436
const fixedDimension = options.width === undefined ? `height` : `width`
438437

439-
// Create sizes for different resolutions — we do 1x, 1.5x, 2x, and 3x.
438+
// Create sizes for different resolutions — we do 1x, 1.5x, and 2x.
440439
const sizes = []
441440
sizes.push(options[fixedDimension])
442441
sizes.push(options[fixedDimension] * 1.5)
443442
sizes.push(options[fixedDimension] * 2)
444-
sizes.push(options[fixedDimension] * 3)
445443
const dimensions = getImageSize(file)
446444

447445
const filteredSizes = sizes.filter(size => size <= dimensions[fixedDimension])
@@ -521,9 +519,6 @@ async function fixed({ file, args = {}, reporter, cache }) {
521519
case 2:
522520
resolution = `2x`
523521
break
524-
case 3:
525-
resolution = `3x`
526-
break
527522
default:
528523
}
529524
return `${image.src} ${resolution}`

0 commit comments

Comments
 (0)