kamsar / Dianoga

An automatic image optimizer for the Sitecore media library.
Other
104 stars 45 forks source link

This is not an issue. Its a question :-) #123

Closed GoranHalvarsson closed 1 year ago

GoranHalvarsson commented 2 years ago

Trying to understand how Dianoga works :-) So it compress images. And then it places it in the image cache on the CM?

So we don't need Dianoga on CD, yes?

Antonytm commented 2 years ago

I will start by explaining how the Sitecore Media handler works.

Sitecore Media Library saves files in the database. It is possible to save them on disk, but honestly, I haven't seen anyone who uses it. Taking files from the database is not a fast operation. Also, when you specify height and width - Sitecore needs to resize an image. Doing it all the time is not fast and is expensive for the CPU.

That is why Sitecore servers(both CM and CD) have a Media Cache folder. Usually, it is "App_Data\MediaCache\", if you don't specify something else. Sitecore saves processed media in that folder. When you request some media file, Sitecore first checks the Media Cache folder. If the cache is found then you get it from a Media Cache. If the cache is not found, you get it from the database. Sitecore doesn't have a mechanism for syncing media cache folders between servers.

Now, back to Dianoga Sitecore is not good at optimizing images(especially it is bad for resized images). Dianoga injects to Sitecore pipelines and optimizes images that are saved in a Media Cache folder.

Dianoga can do it in 2 modes: 1) Sync: you make a request, and before putting the image into the cache, it is proceeded by Dianoga. And put it in the media cache folder. 2) Async: at the first request, you get an image from Sitecore. But Dianoga gets the event and starts processing the image from the cache in async mode. Once it has proceeded, it updates the cache entry in the Sitecore Media Cache Folder.


Conclusion

As Dianoga works around Sitecore Media Cache and you have separated cache on both CD and CM: You do need Dianoga on CD. (On CM depending on your workflow, if you need that CM has the same behavior as CD)

GoranHalvarsson commented 2 years ago

Thanks, great explanation 👍💪