26

After moving the project to the production server, I found that static files, such as images, will not be returned with status "304 not modified", although there are cache headlines like "Last-Modified" and "Expires".

Request Headers

Accept:image/webp,image/*,*/*;q=0.8
Accept-Encoding:gzip, deflate, sdch
Accept-Language:ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4,uk;q=0.2
Cache-Control:max-age=0
Connection:keep-alive
Cookie:_LANG=ru
DNT:1
Host:test.com
If-Modified-Since:Mon, 07 Sep 2015 08:46:37 GMT
If-None-Match:"1D0E949B4DCD480"
Referer:http://test.com/ru/Some/Index/
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML,     like Gecko) Chrome/45.0.2454.85 Safari/537.36

Response headers

HTTP/1.1 200 OK
Cache-Control: public
Content-Type: image/png
Expires: Tue, 08 Sep 2015 14:33:06 GMT
Last-Modified: Mon, 07 Sep 2015 08:46:37 GMT
Accept-Ranges: bytes
ETag: "1D0E949B4DCD480"
Server: Microsoft-IIS/8.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Mon, 07 Sep 2015 14:33:06 GMT
Content-Length: 5953

At the local "IIS express" everything works correctly.

Local response headers

HTTP/1.1 304 Not Modified
Cache-Control:public
Date:Mon, 07 Sep 2015 14:38:12 GMT
Etag:"1D04A9052E17E00"

Prompt, in what could be the reason?

Web.config files are identical.

Thanks!

UPD 1:

chrome network console chrome request

UPD 2:

Local machine cache snapshot returns images

C:\Users\dev>netsh http show cachestate

Snapshot cache responses HTTP::
--------------------------------

URL-address: http://dev2-pc:1437/Views/CustomMeme/byby/img/header.jpg
Status Code: 200
Команда HTTP: GET
Тип политики кэша: Срок жизни (TTL)
Срок жизни записи в кэше (сек): 86399
Время создания: 2015.9.8:12.14.41:0
Имя очереди запросов: Clr4IntegratedAppPool{737BCE3B-FD81-4AB4-B976-A3A8C8A-94D8}
Тип содержимого: image/jpeg
Кодировка содержимого: (null)
Длина заголовков: 415
Длина содержимого: 49017
Число обращений: 3
Принудительное отключение после обслуживания: FALSE

But remote (production) server cache snapshot is empty

C:\Users\Администратор>netsh http show cachestate

Snapshot cache HTTP responses:
--------------------------------
The cache contains entries that match the specified URL-address
dima_horror
  • 3,098
  • 1
  • 20
  • 24
  • 2
    Curious that your request headers include `Pragma:no-cache`. Is your browser set to disable cache while the developer tools are open? – Chris Curtis Sep 10 '15 at 06:59
  • @ChrisCurtis, thanks for your answer, `Pragma:no-cache` does not affect to the response. I update question text and adding some screenshots. – dima_horror Sep 10 '15 at 07:09
  • Is web.config same? Is static cache disabled on production server? There are lot of variables involved in this, ideally, Static Content expiration has to be turned on at IIS level or at web.config – Akash Kava Sep 10 '15 at 08:02
  • @AkashKava web.config's are same. I am tried all settings options, such as http://stackoverflow.com/a/2196848/2114398 , http://stackoverflow.com/a/1566121/2114398 . No results. All indications are that the server settings are different. Perhaps there is a way to compare server settings.. – dima_horror Sep 10 '15 at 09:23
  • Are you running it on IIS Express locally as opposed to IIS 7/8/whatever? – DavidG Sep 10 '15 at 16:46
  • 2
    try using: netsh http show cachestate. This will show information about the files that are currently in the cache. – Vishal Anand Sep 16 '15 at 06:01
  • @VishalAnand , thanks for answer. Local machine cache snapshot returns information about images (works), but on production server cache snapshot is empty. I update question text with commands output. – dima_horror Sep 16 '15 at 08:37
  • 1. Goto IIS >> HttpResponse Header >> Set Common Headers >> check expire content and set after. 2. In Features View, select Output Caching. On the Output Caching page, in the Actions pane, click Edit feature settings. In the Edit Output Cache Settings dialog box, click to select Enable cache – Vishal Anand Sep 16 '15 at 08:47
  • @VishalAnand, 1) expire web content enabled (http://images.professionalaspnet.com/iis7-http-response-headers-set-common-headers-expire-web-content.PNG); 2) Output caching also enabled (http://i.stack.imgur.com/2zVWj.png) ; Cache snapshot still empty =( – dima_horror Sep 16 '15 at 08:57
  • 1
    My guess is that this has something to do with the ETags. Try to disable them on the server and check... – Vi100 Nov 09 '15 at 12:59
  • I agree with @Vi100 that it may have something to do with the ETags. Have you checked to see if the ETag values match in the responses to repeated requests for that same image? If they do not, then that would indicate that IIS or ASP.Net sees the image as modified. See this link for more information: https://en.wikipedia.org/wiki/HTTP_ETag – gpersell Nov 10 '15 at 09:05

2 Answers2

1

Refer Below link and enabling cache manually for contents type based on your requirement and see if its works or not.

https://www.iis.net/configreference/system.webserver/caching

-2

From what I understand, status code 304 means that the server tells the browser, "hey, the image you are requesting has not been changed since xxxx/xx/xx, use your local cache should be fine!". So the discrepancy between your development machine and production server is most likely caused by production server IIS setting.

What you can try for now are:

  • Do "hard reload" to your web page in your web browser (in chrome, you can turn on "developer tool" by click F12, and then right click on the "reload" button, it will give you "empty cache and hard reload" option"
  • On your development machine, try to install IIS instead of IIS express, and run your web application within IIS. There could be some default setting discrepancy between IIS express to your production server IIS, so try to mimic the production server environment on your development machine
  • Try to disable IIS cache explicitly. You can find how to do it here https://serverfault.com/questions/117970/iis-7-returns-304-instead-of-200

Hope this helps! Henry

Community
  • 1
  • 1
Henry Liang
  • 137
  • 1
  • 7