Posted


Blog Programming Tips Azure Infrastructure

In a previous post I wrote about a couple of problems I have with Azure, the main one being the lack of a purge function on the CDN. 

 I want the ability to crop, resize and upload multiple times for the same filename, the lack of a purge function makes it pretty difficult

For a while I have been just using Azure storage to serve and host my images, I recently watched a video that shows how wasteful this could be, and how my speed could dramatically improve if I used the CDN.

I first enabled query strings on my azure CDN.

enablequerystring

When I wrote the uploader I did not add any sort of cache header to the files, this meant that the default was attached. I believe this is 72 hours. I lowered the image default all the way down to 10 minutes.

I then added a version column to my images table in the database

sql

, along with my repositories, mappings and models:

mapping
imageversion

I then added a boolean property onto the form model. This was defaulted to false, when true it will generate a new verion

imageformmodel

This was then added into the front end in my edit partial.

frontend

I used the same method when cropping any new images

croppedversion

Finally I amended my image CDN URL helper methods to add in the version number into the query string.

url

I also had my CDN URL pointing at storage, my last change was the change this back to http://cdn.siliconpanda.com (which points to http://az653594.vo.msecnd.net/ ) and I was done.

cdnurl

I now have a unique image URL when a version exists and when I am using the CDN, I thought about having the version as a incrementing number, but I didn’t really see the point, I don’t need to know the history of the file in the URL. I may replace this with something other than a Guid, but for now it works just fine and ensures it is always unique when an image is re-cropped/ uploaded 

finished

A pretty simple workaround for the missing feature.