strapi-community / strapi-plugin-local-image-sharp

Dynamically resize, format and optimize images based on url modifiers.
https://strapi-community.github.io/strapi-plugin-local-image-sharp/
65 stars 17 forks source link

Cache images? #3

Closed ohbob closed 1 year ago

ohbob commented 2 years ago

Is there a way once requested the image is being cached forever? I don't want to regenerate the image on each call.

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
        <img alt="image" src="http://localhost:1337/uploads/f_avif,q_70,w_920/F_Sp8o_KVIAA_0_U7b_bc59f01efd.jpg">
</body>
</html>
Sandstedt commented 2 years ago

Yes. Set a cache rule on your server.

ohbob commented 2 years ago

Yes. Set a cache rule on your server.

Could you give an example please?

Sandstedt commented 2 years ago

Ngnix: https://linuxhint.com/cache-static-resources-https-nginx/

Apache: https://www.faqforge.com/linux/enable-image-caching-in-apache-for-better-google-page-speed-results/

Sandstedt commented 2 years ago

If your using something like next.js and next/image, there is some cache settings to be set there: In next.config.js you can set the images cache duration. If you have no cache on the server, and haven't set minimumCacheTTL, then you images will get thrown away as soon as they have been generated.

https://nextjs.org/docs/api-reference/next/image#caching-behavior

ohbob commented 2 years ago

do i understand this right, the caching is happening on the client side for the front end? If that's the case, seems a bit odd, that it's not being cached at backend..

Sandstedt commented 2 years ago

Oh sorry, mixed together this issue with a next/image thread I'm getting a lot of updates on. Edited.

Sandstedt commented 2 years ago

But I would recommending using a cache layer in front of this plugin. Wouldn't not expect that's in the scope of this plugin, it has just a single purpose, to generate an images based on the parameters I send to it. See it like a microservice. Cause caching all depends on the rest of the setup in your project. If your using something like Gatsby or Next.js, it will be build into the framework.

c3s4 commented 2 years ago

it has just a single purpose, to generate an images based on the parameters I send to it

The generated image is not saved in the filesystem, am I right?

Thanks

stafyniaksacha commented 2 years ago

You can now set maxAge properly in the plugin setting. Before v1.2.0 this setting were not used by ipx, it was fixed on https://github.com/unjs/ipx/pull/71 so browser cache should now work as expected!

About server side caching, for now images are not stored anywhere. We can extend https://github.com/strapi-community/strapi-plugin-rest-cache to allow caching assets?

ohbob commented 1 year ago

please extend serverside caching of images

kevin-chassagne commented 1 year ago

+1 is this something planned in the future?

ohbob commented 1 year ago

You can now set maxAge properly in the plugin setting. Before v1.2.0 this setting were not used by ipx, it was fixed on https://github.com/unjs/ipx/pull/71 so browser cache should now work as expected!

About server side caching, for now images are not stored anywhere. We can extend https://github.com/strapi-community/strapi-plugin-rest-cache to allow caching assets?

Any progress on this? I really want this to become a reality) how can I help?

stafyniaksacha commented 1 year ago

I do not have too much time to work on this at now, sorry! If someone could open a PR I will take time to review/publish, that would be appreciated.

stafyniaksacha commented 1 year ago

Hello there!

The feature is done in v1.4.0: https://strapi-community.github.io/strapi-plugin-local-image-sharp/guide/#configuration

Also, the new documentation is online! Feedback is welcome!

martin-landhi commented 1 year ago

How do you manage when you change the image? because the reiszed images are cached and not change. How can i flush that specific image cache?