astro-imagetools
astro-imagetools copied to clipboard
[Feature idea] "Auto caching" on hosting platforms using live website
Obviously, caching is an important feature for a tool like this one!
I have a reasonable amount of images on my site and the build time has more than doubled since I refactored to use astro-imagetools
.
Caching locally for development probably isn't so complicated? It seems we just need to look up in the dist/assets
to see if the output we are about to produce has already been produced earlier, then move it in the appropriate place, am I right?
But caching for local development and build may not be that big of a deal. Vite makes the experience reasonably fast.
When it comes to static hosts (like Netlify and many others) however, it becomes a lot more relevant to avoid long build times. Each host probably has its own caching mechanism and it may not be that easy to develop plugins for each one of them.
What if, instead of relying on the host's architecture, we simply relied on the website being online. If we download the whole assets
directory from the live website and put it in a local cache, we could even share the caching retrieval mechanism between the local dev environment and the remote build environment of the host.
Bonus: We probably already have the live website url in the astro.config
's site
property.
Great idea @m4rrc0 :clap: ! Currently, astro-imagetools
caches the images after fetching remote images or generating buffers. So, the benefits of caching start appearing from the second build. It might be a clever way to improve the first build performance. It might not work 100% of the time (because there are other configs that can affect the destination of the assets directory) but it's still a great idea!
But before implementing a feature like this we have to improve our cache invalidation system. Currently, we take only the filename into account when using the cache. This will still work for Auto Caching, but we should improve the logic to use a better technique before implementing it, for instance, checking if the hash or buffer matches.
I am glad you like the idea!
Clearly I have to spend more time using astro-imagetools
because I hadn't noticed the caching mechanism yet.😅 I am tackling too many aspects of my project at the same time to be able to focus I think.
Out of curiosity (if you have time to share your thoughts)... Isn't the filename "good enough"? It contains a hash based on the image generated, right? The chances of getting the same hash on the same original file for a different output are probably one in a million or even less, aren't they?
The chances of getting the same hash on the same original file for a different output are probably one in a million or even less, aren't they?
Million times or even more than that! You are right, it didn't even come to my mind that we are appending a hash to the filenames :sweat_smile: !