Cache images and CSS files in a MVC.Net project


In a MVC.Net project, how is it possible to only cache images and CSS files using Fastly?


In the Fastly configuration for the service you can add a condition targeting only certain file extensions that will make all other requests PASS. If they PASS they won’t be cached in our CDN.

For example if you create a request setting with the ‘Action’ set to ‘Pass’ and then add a condition to it that applies only if req.url.ext ~ "(css|gif|jpg|png)" that will enable what you’re looking for. Feel free to amend the list of file extensions.

Here’s a doc page on creating the setting

(you need the first section – ‘Using a request setting’)

and one on creating a condition

Once you’ve done this you should ensure you’re caching the images and CSS for as long as possible. Check this page out for more info Suggestions for Better Caching

Let us know if you need assistance determining how much things are caching.