google/eleventy-high-performance-blog

Build took too long because one image

hifedixx opened this issue · 5 comments

I'm migrating my blog to Eleventy and tried to deploy it on Cloudflare, but it failed in every build. So I moved to Netlify, and it turns out that my build took up to 30 minutes. And there is a single image that needs 20 minutes itself.

netlifybuild

The pic is about 4MB in size. Is it too big?

Run the npm run build locally on your machine, that will generate all the images needed.
Then run persistimages.sh which will move all generated files to_site/img folder which is persisted during builds.
Make sure you commit the images
When the changes are getting pushed, Netlify picks them up and eleventy hopefully will skip processing the images.
If you send link to the original image then we could probably able to diagnose why this is getting processed so slowly, it's maybe an issue coming from upstream, i'm thinking sharp generally tends to hang when the build happens in a serverless environment.

I don't use remote image, I've downloaded it before and place it in the img folder. But what I get from what you said, we must run persistimage.sh so Netlify doesn't need to proccess the imgs again. Then the build time will be much shorter. Is that right?

You can set .persistimage.sh to be a part of the build process in package.json's script. Mine looks like this:

"build": "npm run js-build && eleventy && ./.persistimages.sh",

+1 This works both for local and remote images.

Thanks everyone! Solved.