Niels-IO / next-image-export-optimizer

Use Next.js advanced <Image/> component with the static export functionality. Optimizes all static images in an additional step after the Next.js static export.
MIT License
439 stars 52 forks source link

Feature request: Don't download again for X days #185

Closed hollowaysmith closed 9 months ago

hollowaysmith commented 10 months ago

The free tier headless CMS I use has 500k image requests every month and with next-image-export-optimizer I'm downloading 5k images every time it builds. That means I can build 100 times every month as it downloads the same images every time.

I understand the justification that the source images may have changed since the last build, but I'd find it really useful if it could not re-download the images for a certain amount of days.

So in summary the idea would be to download new image URLs and preexisting image URLs that were at least X days old, but not more recently downloaded images.

hollowaysmith commented 10 months ago

What do you think of the idea? I'm happy to open a PR and contribute the feature.

Niels-IO commented 10 months ago

Hi @hollowaysmith,

I am open to a PR as long as it wouldn't be a breaking change, and adds only reasonable complexity. We have to think where to put the necessary info.

Maybe the cache duration could be stored in the romnoteOptimizedImages.js file.

Standard (and should be kept working): module.exports = [ "https://reactapp.dev/images/nextImageExportOptimizer/christopher-gower-m_HRfLhgABo-unsplash-opt-2048.WEBP", ];

Optional: Entries are an array with the src and a time to cache: module.exports = [ ["https://reactapp.dev/images/nextImageExportOptimizer/christopher-gower-m_HRfLhgABo-unsplash-opt-2048.WEBP", 3221], ];

The last build info maybe in next-image-export-optimizer-hashes.json?

Niels-IO commented 10 months ago

Hi @hollowaysmith,

You can scrap the first idea. I came up with a simpler mechanism and created #190 for this feature.

holloway commented 10 months ago

@Niels-IO Amazing, thanks! Happy to help test it etc if you want