High bandwidth usage on Gatsby site with Sanity CDN images
29 replies
Last updated: Mar 25, 2021
A
Hi everyone, back again with a bandwidth question. I have a Gatsby site that builds everything at run time but all of the images are served over the sanity CDN (I’m using the
https://www.dropbox.com/s/h32v7tjo3nt5ncu/Screenshot%202021-03-17%20at%2009.02.34.png?dl=0
In the last 30 days the website has had around 1,200 visitors, so not exactly
huge traffic. My usage on Netlify is in the MB’s so it has a tiny footprint there. It’s just Sanity usage which I assume is coming from the images?
Can anyone help me figure this out? I’ve tried lowering the resolution of the images but can’t go much lower without the quality suffering.
I have a theory that users might be having to re-download images every time a new update/build is made to the site, but I have no understanding of how to prove that…
gatsby-sanity-sourceplugin with
gatsby-imagefor this) and the bandwidth usage is sky high vs what I’d expect:
https://www.dropbox.com/s/h32v7tjo3nt5ncu/Screenshot%202021-03-17%20at%2009.02.34.png?dl=0
In the last 30 days the website has had around 1,200 visitors, so not exactly
huge traffic. My usage on Netlify is in the MB’s so it has a tiny footprint there. It’s just Sanity usage which I assume is coming from the images?
Can anyone help me figure this out? I’ve tried lowering the resolution of the images but can’t go much lower without the quality suffering.
I have a theory that users might be having to re-download images every time a new update/build is made to the site, but I have no understanding of how to prove that…
Mar 17, 2021, 9:18 AM
A
Watch your local dev activities, if you disable cache during development & work on a site all day everyday it could really add up
Mar 17, 2021, 10:30 AM
A
Yeah good shout
user G
— the faint blue line on the image I linked above shows last months bandwidth usage during dev, so I can see it’s minimal comparatively. The site only went live at the start of MarchMar 17, 2021, 10:31 AM
A
I see.. have you tried strolling through the site to see how much bandwidth it consumes during a typical visit?
I have a theory that users might be having to re-download images every time a new update/build is made to the site, but I have no understanding of how to prove that…I think if you hit “clear cache & redeploy” it’ll do this, but if you have something like netlify plugin cache the image should be the same on most builds
Mar 17, 2021, 10:33 AM
D
user G
how could I test that using Firefox developer edition?Mar 17, 2021, 1:46 PM
A
Same as in Chromium, Network tab / disable cache / Images
Mar 17, 2021, 1:48 PM
A
Thanks — this is definitely the issue, just doing a quick test and clicking around to a few articles, scrolling through the homepage and “reading” the content, I’ve hit 7mb
Mar 17, 2021, 1:50 PM
A
just from images alone
Mar 17, 2021, 1:51 PM
A
whoops, do you have lots of images?
Mar 17, 2021, 1:51 PM
D
Yeah it’s an editorial website, I just realised I didn’t share the link in my original post: https://dscvrd.co/
Mar 17, 2021, 1:52 PM
A
Might be a quick one to set a max-height on the images being fetched, but generally I’m not sure what else I can do here
Mar 17, 2021, 1:54 PM
D
hhhm maybe you can look into optimizing
sizesattributes? If the projected cost is an issue for you, imgix is a lot cheaper bandwidth wise vs. sanity 🤫
Mar 17, 2021, 1:59 PM
A
I was just looking to see if another image handling service might be better actually
Mar 17, 2021, 1:59 PM
D
You can offload sanity images to something like imgix fairly easily?
Mar 17, 2021, 2:00 PM
D
maybe try using web proxy for a simple integration https://docs.imgix.com/setup/creating-sources/web-proxy
Mar 17, 2021, 2:02 PM
A
I just remembered this: https://images.weserv.nl/
Mar 17, 2021, 2:03 PM
A
Might solve the problem and for free too from what I can tell
Mar 17, 2021, 2:05 PM
A
what the heck? That’s so cool. Thanks for sharing!
Mar 17, 2021, 2:05 PM
A
Mar 17, 2021, 2:05 PM
A
Right?! 😂
Mar 17, 2021, 2:05 PM
A
I remembered I used it on an instagram hook I set up and I just cached all the images through that
Mar 17, 2021, 2:06 PM
A
Seems like it has something to do w the fact that the service is powered by cloudflare? How is cloudflare bandwidth always unlimited, I could never understand
Mar 17, 2021, 2:09 PM
A
Yeah and they’re using it to test out image manip features so I guess you’re handing over your data in that respect
Mar 17, 2021, 2:10 PM
A
mmhmm, good point
Mar 17, 2021, 2:11 PM
A
But all the image data is public anyway in my case
Mar 17, 2021, 2:11 PM
A
Hey
user S
I’m experiencing the exact same problem. It appears that gatsby-sanity-sourceisn’t adding the
auto=formatto the source image
Mar 24, 2021, 7:28 AM
A
This can be helped by using https://www.sanity.io/plugins/gatsby-plugin-sanity-image , which does add this flag by default
Mar 24, 2021, 7:29 AM
A
user S
What does that auto=formatflag do?
Mar 25, 2021, 12:10 PM
A
Some good reading here: https://www.sanity.io/docs/image-urls
Mar 25, 2021, 9:55 PM
A
Setauto=formatto automatically return an image inwebpformatting if the browser supports it.
Mar 25, 2021, 9:56 PM
Sanity– build remarkable experiences at scale
Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.