I want my static content (images, javascript files, css files etc) to served in full only after the file has been updated.
If a file has not changed since it was last requested (as determined by the ETag and Last-Modified response header values) then I want the cached versions of the files to be used by the client browser.
Does Nancy support this functionality?
Nancy does partially support the
ETagand theLast-Modifiedheaders. It sets them for all static files but as of version 0.13 it does nothing with these values. here is the Nancy code:Nancy.Responses.GenericFileResponse.cs
To make use of the
ETagandLast-Modifiedheader values you need to add a couple of modified extensions methods. I borrowed these directly from the Nancy source code in GitHub (as this functionality is planned for a future release) but the original idea came from Simon Cropp – Conditional responses with NancyFXExtension Methods
Finally you need to call these methods using the
AfterRequesthook in your Nancy BootStrapper.BootStrapper
Watching the responses with Fiddler you will see the first hit to your static files downloads them with a
200 - OKStatus Code.Thereafter each request returns a
304 - Not ModifiedStatus Code. After a file is updated, requesting it once again downloads it with a200 - OKStatus Code … and so on.