Skip to content
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

Cache generated images? #522

Closed
kevinrenskers opened this issue Mar 27, 2023 · 8 comments · Fixed by #661
Closed

Cache generated images? #522

kevinrenskers opened this issue Mar 27, 2023 · 8 comments · Fixed by #661

Comments

@kevinrenskers
Copy link

I'm using vite-imagetools in a SvelteKit project, and due to the many images that the site is using, creating a build takes almost 3 minutes. When I remove the vite-imagetools plugin, creating a build takes about 20 seconds. This is a huge huge difference, and it kind of doesn't make sense to me that the images are getting generated with every single build, as the source images basically never change.

Is there a way to cache the generated images, so that when you create the next build, it can just reuse the earlier generated images instead of having to create them all over again?

@benmccann
Copy link
Collaborator

Would someone be able to try the caching plugin and let me know if it works this use case? vitejs/vite#10671 (see the "Try it" heading for instructions on setting it up)

@ArnaudBarre
Copy link

Hi! Vite team member here.
One of the reason we decided to currently not continue experimenting with caching is that because it's global, cache invalidation will happen too often (lock update, config update or even some env update). Plus the caching was only for dev.
So for the now the idea is: making core fast, let plugins with slow process do caching. In the future we may provide helpers to help plugin authors deal with caching (apparently something that Parcel does well) but for now you will be on your own.

@JonasKruckenberg
Copy link
Owner

Yeah we had on-disk caching in the 1.x version of this plugin (it was actually disk first) but maintaining that folder and purging old images was a total nightmare.
Maybe I'm missing something and it has been years since I last did something like this but the only obvious solution that comes to mind is maintaining some sort of cache manifest 🤔
Or maybe iterating through and checking the lastModified time though I don't know if that would cause weird issues with CI builds

@benmccann
Copy link
Collaborator

Thanks for the update @ArnaudBarre. I know we decided not to merge anything in Vite core to deal with caching at the moment, but wasn't sure what thoughts were around it longer term - e.g. whether you might be maintaining the caching plugin or revisiting that approach if we find places where Vite still has opportunities for improvement.

@JonasKruckenberg
Copy link
Owner

Yeah so regardless I kinda don't want to deal with implementing caching. I absolutely see the benefit but as I stated earlier last time around it was a nightmare.
If someone wants to submit a PR for it I would be happy to get it across the finish line and released.
Having this be exposed by vite as part of the plugin API though would be obviously ideal

@benmccann
Copy link
Collaborator

benmccann commented Oct 29, 2023

See vitejs/vite#14333, which implements a plugin hook for caching. Since we not only generate code for the file returned by load, but also generate additional files in load, we'd probably have to implement this hook on our own and couldn't rely on the general implementation unless it's made asset-aware somehow

@Robin-Sch
Copy link

Any update for this? I have 71 images and the build time is approximately 15 minutes. If I exclude them it's "just" 2 minutes.

@julien-blanchon

This comment was marked as duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants