I have an ASP.NET MVC website hosted in Azure AppService and am trying to enable caching of dynamic images (served using the Controller # File () method) on the client side. For this, I used several methods:
Converted a URL based on a query string to a "classic" URL, for example.
/file/i/Supplier/Logo/fed88a06-1157-4bbb-826d-365bdd8c89eb/png/cng.png
I am using the IIS rewrite module to convert it back to the query string URL.
The following action method attribute is added that returns an image:
[OutputCache(Duration = 31536000, Location = System.Web.UI.OutputCacheLocation.ServerAndClient)]
- Finally, I forcibly included status 304 in all image requests, where the If-Modified-Since header contains a date that is less than 300 days ago (images do not change often).
It works in all web browsers except Safari 10 and iOS 10. Images are neatly stored in files Sarafi 9, 8, 7, iOS 8.3.3, Chrome, Edge, Firefox, but in Safari 10 they are almost never cached (on iOS 10 too, but it’s not so important). This condition can be played on two physical Mac laptops, as well as on the Mac VM in a browser. Safari caching is not disabled.
Is there anything special about Apple’s latest web browsers that they don’t cache resources as expected? Or am I doing something wrong?
I don’t know how to view the request and response headers in Safari (is this possible at all?), But in Chrome the request and response headers are as follows.
I removed the Host, Referrer, and Cookie headers for clarity.
First start
Inquiry
Accept:image/webp,image/*,*/*;q=0.8
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8,ru;q=0.6,sr;q=0.4
Cache-Control:no-cache
Connection:keep-alive
DNT:1
Pragma:no-cache
User-Agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36
Answer
Cache-Control:private, max-age=31533495
Content-Length:32300
Content-Type:image/png
Date:Mon, 17 Oct 2016 14:58:59 GMT
Expires:Tue, 17 Oct 2017 14:17:13 GMT
Last-Modified:Mon, 17 Oct 2016 14:17:13 GMT
Vary:*
X-Frame-Options:SAMEORIGIN
Second launch
Inquiry
Accept:image/webp,image/*,*/*;q=0.8
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8,ru;q=0.6,sr;q=0.4
Connection:keep-alive
DNT:1
If-Modified-Since:Mon, 17 Oct 2016 14:17:12 GMT
User-Agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36
Answer
Request URL:http:/file/i/Supplier/Logo/1f70c0ac-309c-4629-9186-6ee1b3700d3e/png/crown-logo.png
Request Method:GET
Status Code:304 Not Modified
Cache-Control:private, max-age=31533237
Date:Mon, 17 Oct 2016 15:03:15 GMT
Expires:Tue, 17 Oct 2017 14:17:12 GMT
Last-Modified:Mon, 17 Oct 2016 14:17:12 GMT
Vary:*
X-Frame-Options:SAMEORIGIN