Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Christina 127 posts 390 karma points notactivated
    Nov 18, 2020 @ 09:38
    Christina
    0

    Using Slimsy and Azure CDN - can't change image size, renders to small images maybe I missing something

    Hi I'm using Slimsy to render webp images and everything works fine, but when I try to use CDN on Azure this guide https://github.com/Jeavon/Slimsy/blob/dev-v3/Docs/Azure-CDN/index.md I can't change images size, my images renders in same size whatever I do. I have latest slimsy 3 and imageProcessor 4.12.1. Using Azure Blobstorage //Many thanks in advance Christina

    razor: <img src="@SlimsyExtensions.GetCropUrl(image,width:930,height:350, imageCropMode:ImageCropMode.Crop,useCropDimensions:true,upScale:true)" />
    Render: <img src="https://cdn.mysite.com/media/ys1fnlqg/dji-0049-original-161428-1.jpg?center=0.647140985056436,0.47462807317182792&amp;mode=crop&amp;width=450&amp;height=250&amp;rnd=132338741215630000">
    
  • Marc Goodson 2157 posts 14431 karma points MVP 9x c-trib
    Nov 18, 2020 @ 20:16
    Marc Goodson
    0

    Hi Christina

    My first thought was that in Azure CDN that you haven't got 'cache every unique' url set properly, so a request for

    https://cdn.mysite.com/media/fish.jpg?width=90

    would be the same as a request for

    https://cdn.mysite.com/media/fish.jpg?width=180

    the cdn wont see the difference in the querystring and return whichever was the first one requested... also you'll need to purge your CDN if you've changed that setting after an image has been requested....

    But the strange thing is via the slimsy extension you are requesting a version of the image that is 930px wide but the Url is being written out with width 450px!

    All the Slimsy extension is doing is writing out the CDN of the domain before the result of calling the core, Url.GetCropUrl method...

    ... So I wonder what happens if you temporarily hardcode the url in your razor file - do you get the correct image from the CDN, if you vary the width do you get a different correctly sized image?

    If not it will tell you the problem lies with the configuration of the CDN - but if the CDN is returning the correctly sized images for the request, the issue is somehow in the Slimsy extension generating the Url - is there any other caching in play in the view/macro that is writing out the link?

    So either the CDN is caching all variations on the querystring as the same request, or ImageProcessor isn't correctly processing the image when it's not in the CDN - you can test this by requesting the image directly on the url of your site instead of via the CDN - when you go direct - does the image change size correctly in response to different querystring parameters?

    regards

    marc

  • Christina 127 posts 390 karma points notactivated
    Nov 20, 2020 @ 16:22
    Christina
    0

    Hi Marc Big Thanks for helping me out. This is what happens The CDN is caching all variations on the querystring as the same request and showing the smallest. If I test without CDN and add querystring parameters it works fine. My problem is that every image from CDN is very small, I have tried to purge. Nothing happens. I have hardcoded the image from CDN and it's the same small size. So the CDN is caching all variations on the querystring as the same request. I must have done something wrong in config but I'm not sure what.

    Many Thanks Christina

  • Marc Goodson 2157 posts 14431 karma points MVP 9x c-trib
    Nov 20, 2020 @ 17:51
    Marc Goodson
    100

    Hi Christina

    Usually when this happens for me I've forgotten to set the 'Query string caching behavior' option

    It's on the Caching Rules section if I remember correctly of the CDN Settings in azure.

    It needs to be set to 'Cache every unique URL'

    is that how you have it?

    The second thing that is common to have an issue with is setting the source for the CDN - this needs to point to your site's media folder - often people will kind of point it directly to the blob storage (as that's another way to setup a CDN when you have static assets) - and then Image Processor isn't doing any magic image resizing, it's just cached direct from blob, so the querystring parameters have no effect.

    So in your templates you should be requesting your image via the cdn

    <img src="https://cdn.mydomain.com/media/13232/fish.jpg?width=100" />
    

    And the CDN will serve this directly if it's served it before

    If not, it should request the image from your site, eg make it's own request to

    https://yoursite.com/media/13232/fish.jpg?width=100
    

    and then Image Processor should handle the request and do the resizing magic - it will read the image from wherever you have media configured to be in: /config/filesystemproviders.config and then cache the processed image in wherever you have the cache configured... /config/imageprocessor/cache.config and return the processed image to the CDN for future requests.

    one other common gotcha is if you have the image processor cache configured to be blob storage - then by default it returns a redirect, that CDNs prefer not to cache, but there is an option called StreamCachedImage that you can set to avoid this in /config/imageprocessor/cache.config (but only if you are using blob storage for the cache) - and the cache is nothing to do with the CDN! if you purged your CDN and a request came in for an image that had been requested before, ImageProcessor would look in it's own cache first before processing - but with the CDN in place this shouldn't really ever happen!

    Hope it's one of the things above!

    regards

    Marc

  • Christina 127 posts 390 karma points notactivated
    Nov 23, 2020 @ 07:36
    Christina
    1

    Hi Marc

    Many Thanks for helping me out It works! I had forgott to set Cache every unique URL.

    /Christina

Please Sign in or register to post replies

Write your reply to:

Draft