-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: use file hashes to download the same asset only once #12080
Comments
We generate file names in |
It looks like it's not possible for me to set the exact same arguments in both places. Here is my
Here is the comparable portion of my GraphQL query to generate images for my front page (not from markdown):
So we have 2 differences:
(Of course I don't know how those config arguments are passed down to plugin-sharp, maybe the issue is not either of those ones but something else entirely. For example, I'm unable to define the return types in gatsby-config, so they might be different.) Source for a demo: https://github.com/baobabKoodaa/blog/tree/temp384 Here is a demo consistent with that source: https://happy-euler-ccaeea.netlify.com/dont-send-your-own-email/ |
Even if it's possible to fix this by modifying |
Well gatsby-transformer-sharp is generating the tracedSVG transformations in a different way this is why the This also extends to cache (meaning it should avoid transforming those twice) because cache in gatsby is not global but a per plugin level one. So if a plugin generates an image and then another plugin generates the same image the cache won't actually see it. I am not sure what the correct solution would be here. |
Ok so this in the end is more tightly related to my plugin and recent changes in sharp. proposed solution is to
|
I think my issue(closed by @gatsbot but still valid afaik) is related to this. I had added a feature to support different sized base64 images, however nothing else about the queries were different, yet the build seems to process the images a 2nd time instead of realizing by cache that it's been done before and only needs to handle the base64 images that have different dimensions.
I'm not aware of the recent changes since. I'll have to test it again and see if it's been fixed or if my feature was implemented incorrectly too causing the behaviour. |
This should be solved by PR #12129 |
…g args (#12129) So continuing on the work to make gatsby-plugin-sharp friendly on third-party packages (oorestisime/gatsby-remark-rehype-images#2) we now face this issue #12080 TL;DR images generated from transformer-sharp or and other plugins are the same (same sha256) but with different hash (depends on the available options). The problem is that all the plugins leak their options into the hash generation and even ones that are unrelated to the resizing processing (base64, generateTraceSVG, traceSVG etc) I've been discussing this with @pieh for the last 2-3 hours :D Proposed solution was to sanitize the args based on a whitelist, which is implemented on the PR. Which leads to the first question: - is it ok if after this release _all_ image hashes are changing? By doing so it can also potentially help lazy image processing @wardpeet by getting rid of unrelated options when persisting jobs. Anyway current state of the PR is that it kind of works, i ve tested this in websites using my plugin and other that not. The issue here is that there are some differences in the number of images created when this modification is on or not. I also verified that public folder doesn't contain duplicate images: `find public -regex ".*\.\(jpg\|webp\|png\|jpeg\)" -type f -exec sha256sum {} \; | cut -d ' ' -f 1 |sort| uniq -d | wc -l`
Still experiencing this issue. Steps to reproduce:
|
Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open! Thanks for being a part of the Gatsby community! 💪💜 |
Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open! As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing! Thanks for being a part of the Gatsby community! 💪💜 |
Hey again! It’s been 30 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it. Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing! Thanks again for being part of the Gatsby community! |
Summary
If a static file is downloaded and cached in the browser, it shouldn't be downloaded again. The browser should just serve it from cache. Currently this is not working as it should, because separate GraphQL queries generate separate sets of assets - even when the output files are exactly same. This means that the exact same file will be generated into different paths, so the browser has to download the same file from multiple paths.
More information
I've put up a live demo at https://stoic-raman-037869.netlify.com/
When I go to the front page, my browser fetches this image. When I click on the image and go to the article page, the browser again fetches the exact same image from a different path.
These are the exact same file:
An easy way to fix this issue would be to place all generated static files into the same folder and make the file hash a part of the filename. This way the second generation of this image would simply overwrite the first generation. And any page which needs this image would reference the same file, allowing the browser to cache it efficiently and avoid downloading the same asset multiple times.
In addition: I'm all ears if anybody knows how I can make this work for me now without forking Gatsby?
The text was updated successfully, but these errors were encountered: