kamsar / Dianoga

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

WebP optimizer doesn't run when CDN config enabled #95

Closed sandycurrie closed 3 years ago

sandycurrie commented 3 years ago

Version of Dianoga

5.4.0

Environment description

Sitecore.NET 9.3.0 (rev. 003498) November 13, 2019 .NET Framework 4.7.1

What configs you have enabled

Reproducible steps (1... 2... 3...) that cause the issue

Enable the configs, specifically for WebP + CDN and try to load any page with images.

What you expected to see, versus what you actually saw

Expected: To see images being pulled down in webp format Actual: Images are received in optimized formats (jpeg, png, etc), but not in webp.

Relevant logs

Only see logs similar to: 19512 14:08:42 INFO Dianoga: optimized /Images/Your-career/Industries/industry_community-service-not-for-profit.jpg [original size: 7917 bytes] [final size: 7801 bytes] [saved 116 bytes / 1.47 %] [Optimized in 343ms] [Extension jpg]

Comments

Disclaimer - I am a Sitecore Novice, but experienced in .NET

I can see that when the CDN config is enabled the MediaProvider adds extension webp as a URL param. This should trigger the webp optimizer in the MediaRequestHandler

My first issue is that the MediaProvider doesn’t appear to run. But after thinking about how this is all supposed to work. I have a bigger question. And I am probably missing something, but even if this all work properly, won’t the first response still get cached in the CDN? And the MediaProvider only run the first time the image is requested? And is that what we really want?

Any help would be greatly appreciated 🙏

markgibbons25 commented 3 years ago

It seems you might have missed some steps / misunderstood some steps in the configuration - please check this community blog post https://www.vinayjadav.com/posts/webp-for-sitecore-with-dianoga and let me know how you go.

sandycurrie commented 3 years ago

Hi @markgibbons25, I'll look through this again in more detail to see if it sorts out my issue of the MediaProvider not running, but it doesn't really answer my main question of how this is expected to work with a CDN. Once the webp optimization has been run (syncronously) for the first request, and that is served to the user, should we expect everyone to then be served this webp optimized image from the CDN?

sandycurrie commented 3 years ago

Sorry, another question @markgibbons25, In the blog post it mentions to enable GetMediaStreamSync with CDN:

Also, you can enable Dianoga.Strategy.GetMediaStreamSync.config.disabled

But in another issue you mention not to enable GetMediaStreamSync with CDN.

Just wondering which is correct?

sandycurrie commented 3 years ago

Hey, Sorted out both my issues. Being a SiteCore newbie I didn't realise the MediaProvider would run when the page is served to the browser. So the extension=webp is on the URL. 👍

Still not sure on my second question. I've disabled Dianoga.Strategy.GetMediaStreamSync.config and everything seems to work. But even your README says to enable this when using a CDN... Should it be enabled? or should the docs be updated?

markgibbons25 commented 3 years ago

The readme says review and enable Dianoga.WebP.CDN.config.disabled - its not clear on purpose as it would be good to have an understanding of the difference between what Dianoga.Strategy.GetMediaStreamSync.config and Dianoga.WebP.CDN.config does. But basically you should disable Dianoga.Strategy.GetMediaStreamSync.config if you enable Dianoga.WebP.CDN.config. Let me know if you have some feedback on what I should change this to so that it fits most people's use case.

sandycurrie commented 3 years ago

I'm not sure how to word it, but I would review this part of the readme where it says:

However, for folks using CDNs those sources must be sent the optimized version of the media immediately. For these situations, you can enable Dianoga.Strategy.GetMediaStreamSync.config.disabled and disable Dianoga.Strategy.MediaCacheAsync.config.

Maybe to say to disable both?

sandycurrie commented 3 years ago

Maybe something like:

However, for folks using CDNs those sources must be sent the optimized version of the media immediately. To ensure this is the case you should disable Dianoga.Strategy.MediaCacheAsync.config. The CDN config already enables the GetMediaStreamSync by default, so you should make sure to disable Dianoga.Strategy.GetMediaStreamSync.config as well.

sandycurrie commented 3 years ago

Thanks for the chat. I'll just close this off now