vnbaaij / Baaijte.Optimizely.ImageSharp.Web

Use SixLabors.ImageSharp.Web in Optimizely
Apache License 2.0
17 stars 15 forks source link

FEAT: Process and serve External Image (and cache result) #26

Closed MikaelPorttila closed 5 months ago

MikaelPorttila commented 5 months ago

Is your feature request related to a problem? Please describe. In some cases image content is not served directly from the Optimizely instance but fetched from an external page.

An example could be a page which display cision news and you are not always able to control the image format or compression which get served but you still want to optimize those images because they are shown on a highly visited page.

Describe the solution you'd like A function which follows the same pattern as the @Html.ProcessImage(), lets call it @Html.ProcessExternalImage() which can be chained just like the regular ProcessImage UrlBuilder but instead of looking for media in the CMS it would fetch the external url and the whole request would be routed through Optimizely CMS where the same cache as for ProcessImage would be checked.

If the image is not in the cache the addon will fetch the image and apply all the transformations in the function chain, cache the result in the same way as ProcessImage does and serve the transformed image to the client.

! There must also be some sort of whitelist of domains which can be proxy-requested this way to prevent unwanted proxy requests from the server.

Describe alternatives you've considered No other solutions within Optimizely or the addon, one option with our infrastructure would be to add a ImageProfiler in our Azure Proxy CDN but I like the idea that Optimizely and the addon serves optimized images even in cases when the Azure Proxy CDN is not used locally.

Additional context In our solution we fetch external images in two cases, news and listing of career opportunities from external web so I can image that the need for such a feature is not uncommon.

Thanks in advance and for an awesome addon, already using it for WebP-encoding of our CMS hosted image media files! 🔥

MikaelPorttila commented 5 months ago

Did some digging and realized that this change doesn't belong in this addon, the change should be done in ImageSharp.Web, close to the middleware. Thanks for this time!