statamic / ssg

The official Statamic Static Site Generator
230 stars 23 forks source link

Slow when using Reponsive Images addon #56

Closed jasonvarga closed 2 years ago

jasonvarga commented 3 years ago

Related to #55

The responsive images seems to generate more variants than I would have expected. Need to work out why, and really understand the rationale behind which variants should be generated and make the ssg use those somehow.

The addon has to do with browser size. Since there's no browser, we might need to fake something.

(@riasvdv - You don't have to spend any time on this, but if any of this sounds familiar to you, a tip in the right direction would be helpful)

riasvdv commented 3 years ago

The addon doesn't use browser size to determine the variants, it uses a fairly straightforward "WidthCalculator" that determines the ideal px/kb ratios for generating images and lets the browser pick the best one based on how wide the image is displayed.

https://github.com/spatie/statamic-responsive-images/blob/master/src/WidthCalculator.php

It is a big performance hit though, and on my sites I don't enable asset caching, so they're only generated when they're actually requested (through the Glide url). I do understand that's not really a possibility for SSG as it needs those cached images.

One way to improve the performance of responsive images is to generate variants from large to small, and use a larger variant as the source for the smaller one, if you have a source image of 2000px wide, right now it always uses the 2000px one, even if you're generating a 200px one, while it would be faster to use the 250px generated variant (for example) as the source instead, but I haven't found a way to do this yet.

lokmanm commented 3 years ago

I just stumbled upon this, for a site with 10 pages and a lot of images it took 5 minutes to build the website.

Does glide has the same issue or not ? Thanks.

BobWez98 commented 2 years ago

Any updates on this? I have seen a complete server go down when resizing images, any way to improve this?