Http cache with https protocol - http

I've set up cache for my rails application. I use conditional cache with ETag and Last-Modified headers for few pages and browser cache with Cache-Control header for few other pages. It is working ok.
But, after we set up ssl for our server, browser dont want to get pages from cache. I see the same headers for http and https protocols, but for http protocol in Chrome Developer tools in network panel I see status code 200 (from cache) for cached pages, but 200 OK for these pages with https protocol. Here is list of request headers:
Accept:text/html, */*; q=0.01
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8,ru;q=0.6
Connection:keep-alive
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Cookie: ...
Referer: ...
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1712.3 Safari/537.36
X-PJAX:true
X-PJAX-Container:#pjax-container
X-Requested-With:XMLHttpRequest
Query String Parametersview sourceview URL encoded
And response headers:
Cache-Control:max-age=600, public
Connection:keep-alive
Content-Encoding:gzip
Content-Type:text/html; charset=utf-8
Date:Wed, 20 Nov 2013 10:38:07 GMT
Last-Modified:Wed, 20 Nov 2013 08:41:45 GMT
Server:nginx/1.1.19
Set-Cookie: ...
Status:200 OK
Transfer-Encoding:chunked
X-Content-Type-Options:nosniff
X-Frame-Options:SAMEORIGIN
X-Request-Id:71c60772-bc9f-4080-98ad-0c75c589043a
X-Runtime:0.047251
X-UA-Compatible:chrome=1
X-XSS-Protection:1; mode=block
For conditional cache I have similar problem. Server set Last-Modified header, but for next request browser doesn't send 'If-Modified-Since' header, because of it conditional cache doesn't work. And it is working ok for http protocol. Here is list of request headers:
Accept:application/json, text/plain, */*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8,ru;q=0.6
Connection:keep-alive
Cookie: ...
Referer: ...
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1712.3 Safari/537.36
X-CSRF-Token: ...
And response headers:
Cache-Control:max-age=0, private, must-revalidate
Connection:keep-alive
Content-Encoding:gzip
Content-Type:application/json; charset=utf-8
Date:Wed, 20 Nov 2013 10:41:33 GMT
Last-Modified:Wed, 20 Nov 2013 10:20:44 GMT
Server:nginx/1.1.19
Set-Cookie: ...
Status:200 OK
Transfer-Encoding:chunked
X-Content-Type-Options:nosniff
X-Frame-Options:SAMEORIGIN
X-Request-Id:35054727-1b1a-497d-a830-6499ed9cad7a
X-Runtime:0.012432
X-UA-Compatible:chrome=1
X-XSS-Protection:1; mode=block
Browser caches css and js files from this server, but not rendered pages. Why browser dont cache pages for https protocol? How I can make browser cache these pages?

Related

Http request header "Accept-Charset" is not recognized

I am trying to make a REST call using chrome DHC and Advanced rest clients. For example:
A HEAD call to http://www.google.co.in
using advanced REST client gives:
Redirect To:https://www.google.co.in/ with status: 302 Show explanation HTTP/1.1 302 Found
Redirection information has not been cached.
Location: https://www.google.co.in/
Cache-Control: private
Content-Type: text/html; charset=UTF-8
Date: Fri, 29 Nov 2013 06:57:46 GMT
Server: gws
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Alternate-Protocol: 80:quic
Content-Length: 222
Proxy-Connection: Keep-Alive
Connection: Keep-Alive
Status
200 OK Show explanation Loading time: 764
Request headers
Accept: application/json
Accept-Language: en-US
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36
X-Chrome-Variations: <some value>
Accept-Encoding: gzip,deflate,sdch
Cookie: <some value>
Response headers
status: 200 OK
version: HTTP/1.1
alternate-protocol: 443:quic
cache-control: private, max-age=0
content-encoding: gzip
content-length: 34821
content-type: text/html; charset=UTF-8
date: Fri, 29 Nov 2013 06:57:46 GMT
expires: -1
server: gws
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
I am more interested on details of request header as "Accept-Charset" is not recognized. If i give anything as header it is atleast displayed in request header. Now some questions:
why this is not recognized? is this client problem or server problem? do i need to use any other client. I am not aware.
If it is recognized then I should be able to validate this value in server code, which in my case is running in jetty?
Thanks,
Akhi
I found that its a client problem, specific to Chrome. I dont know why with chrome this header is completely ignored.
When i tried to send http request using CURL command, i was able to retrieve this header. Now i can go ahead with validation of "Accept-Charset" header.

Why are browsers not caching these static files

my question seems duplicate of this
but I am having a case
when I refresh a page with F5 then images are not getting fetched from cache instead request is going to server and server responding 304 status code(not modified)
but if I type a URL in address-bar or navigate page from browser back/forward button then images are coming from cache.
but I am having one doubt here why request is made for cached images to origin server on F5 (page refresh)
Nginx configuration
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires 2d;
proxy_pass http://localhost:3001;
break;
}
Request header
===================================
GET /assets/first_banner.png HTTP/1.1
Host: localhost:3000
Connection: keep-alive
Cache-Control: no-cache
Pragma: no-cache
Accept: image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.65 Safari/537.36
Referer: http://localhost:3000/
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
===================================
Response header:
===================================
HTTP/1.1 200 OK
Server: nginx/1.1.19
Date: Sun, 08 Dec 2013 20:31:06 GMT
Content-Type: image/png
Content-Length: 141498
Connection: keep-alive
Cache-Control: max-age=172800
Last-Modified: Wed, 23 Oct 2013 05:34:11 GMT
Etag: "0fc96d0218a47398d37dacca76916727"
X-Ua-Compatible: IE=Edge
X-Request-Id: 48d1ec3a24e2c0f13250ea74101f6753
X-Runtime: 0.021479
Expires: Tue, 10 Dec 2013 20:31:06 GMT
===================================
When you hit F5 you tell the browser to check the webserver if the content, cached locally or not, is still valid.
If the object is expired on the webserver then the browser fetch the asset again. If the object is still valid, the local browser-cached content is used.

Page over http gets cached while over https it doesn't

I have a webapplication. The bootstrap page shouldn't be cached but chrome always gets the page from cache, while it doesn't show that behaviour over https, where it works correctly.
My headers are as follows:
Request URL:https://localhost:7002/
Request Method:GET
Status Code:200 OK
Request Headersview source
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8,de-CH;q=0.6,de;q=0.4
Cache-Control:max-age=0
Connection:keep-alive
Host:localhost:7002
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.56 Safari/537.36
Response Headersview source
Cache-Control:no-cache
Content-Length:2215
Content-Type:text/html; charset=UTF-8
Date:Tue, 23 Apr 2013 10:19:03 GMT
Expires:Thu, 01 Jan 1970 00:00:00 GMT
Pragma:no-cache
Set-Cookie:JSESSIONID=WrSkR2gXB3Jkycwhtzmhwgkpzv4Nn1V6nshsMWZyHl924cNp6Y6L!-1407827785; path=/; HttpOnly
Vary:Accept-Encoding
X-Powered-By:Servlet/2.5 JSP/2.1
The headers over http are exactly the same.
I tried already max-age, no-store, must-revalidate, ETag, Last-Modified, Pragma in the HTTP Header and in the meta http-equiv, but nothing seems chrome to prevent caching.
Any ideas how to prevent chrome from caching?
PS: Safari on iOS shows the same behaviour.

Why could a browser not caching a resource with Cache-Control HTTP headers?

I've read all the caching documentation for HTTP, and this are the headers for my file:
Edit: I am now using amazon S3 to see if it helps and still the same problem! Here go the request and the response> What am I missing? Even thought the response asks for the browser to cache the file, it doesn't! I've checked the Google Chrome cache and the file is not there.
Request URL:https://s3-sa-east-1.amazonaws.com/combo-combat-release/WebPlayer.unity3d
Request Method:GET
Status Code:200 OK
**Request Headers**
GET /combo-combat-release/WebPlayer.unity3d HTTP/1.1
Host: s3-sa-east-1.amazonaws.com
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17
Accept: */*
Accept-Encoding: gzip,deflate,sdch
Accept-Language: es,en-US;q=0.8,en;q=0.6
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
**Response Headers**
HTTP/1.1 200 OK
x-amz-id-2: xu/RKgR4Xt6G3jQ1qkdO5rzd4TlngDYYERZ+bbGlalitJFMDjAgiLAoP4GXhmkeo
x-amz-request-id: 6A9389D16407D28D
Date: Wed, 16 Jan 2013 22:42:26 GMT
Cache-Control: max-age=2592000, public, must-revalidate
Last-Modified: Wed, 16 Jan 2013 22:29:55 GMT
ETag: "0f8d22257da9fcae61f21fd30b7a1fd4"
Accept-Ranges: bytes
Content-Type: application/octet-stream
Content-Length: 39222189
Server: AmazonS3
But the browser doesn't cache the file. Each time, the request is sent and all the data transferred from scratch (200 OK instead of 304). :(
File size is 37.4 MB
Any tip on what could be wrong?
Thanks,
Manuel
Try HTTP 1.1 instead of 1.0.
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html states:
Note that HTTP/1.0 caches might not implement Cache-Control and
might only implement Pragma: no-cache

Why is a page retrieved from cache?

When pages on our website are updated and we load them in the browser they are never reloaded (until I explicitly refresh).
The first time I load Chrome Developer Tools just says "(from cache)" and doesn't show any headers but I reckon they should always send a request to validate the ETag. Or maybe the server sends a 304 Not Modified response status in error but this doesn't show up in the Network tab.
When I refresh, these are the headers. Anyone sees what is wrong?
Request
GET /home/index.html HTTP/1.1
Host: *******.be
Connection: keep-alive
Cache-Control: max-age=0
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Referer: http://*****.be/home/index.html
Accept-Encoding: gzip,deflate,sdch
Accept-Language: nl-NL,nl;q=0.8,en-US;q=0.6,en;q=0.4
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
If-None-Match: "c38f300d-114d-4c2565b57b420"
If-Modified-Since: Wed, 13 Jun 2012 08:27:42 GMT
Response
HTTP/1.1 304 Not Modified
Date: Wed, 13 Jun 2012 11:24:52 GMT
Server: Apache
Connection: close
ETag: "c38f300d-114d-4c2565b57b420"
I have tested this with Chrome 19 and IE9.

Resources