Cache images and CSS files in a MVC.Net project


#1

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


#2

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

https://docs.fastly.com/guides/vcl/understanding-the-different-pass-action-behaviors

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

and one on creating a condition

https://docs.fastly.com/guides/conditions/using-conditions

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.