André Gil
André Gil

Reputation: 624

HTTPS images not caching

I'm having some problems with caching images on my web app. The images are cached after refreshing, but when I reopen the browser it's not cached anymore. I'm using HTTPS, but I'm not sure it's the problem. This is the response from the server:

Response Headers
Accept-Ranges: bytes
Cache-Control: public
Connection: close
Content-Length: 3711
Content-Type: image/png
Date: Mon, 21 May 2012 14:08:46 GMT
ETag: "446b5-e7f-4c0559b8c1c9f"
Expires: Wed, 20 Jun 2012 14:08:46 GMT
Last-Modified: Fri, 18 May 2012 20:43:41 GMT
Server: Apache/2.2.22 (Amazon)

And our httpd.conf

NameVirtualHost *:80
NameVirtualHost *:443

<VirtualHost *:80>
    ServerName [REMOVED]

        RewriteEngine on
        ReWriteCond %{SERVER_PORT} !^443$
        RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]
</VirtualHost>

<VirtualHost *:443>

ServerName [REMOVED]

#Force image type
AddType image/png .png
AddType image/jpeg jpeg jpg jpe
AddType font/x-woff .woff

#Cache
ExpiresActive On
ExpiresDefault A0
<FilesMatch "\.(png|jpg|jpeg|gif)$">
    ExpiresDefault "access plus 1 month"
    Header set Cache-Control "public"
</FilesMatch>

#Logs
ErrorLog logs/ssl_error_log
TransferLog logs/ssl_access_log
LogLevel warn

#SSL
SSLEngine on
SSLProtocol all -SSLv2
SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW
SSLCertificateFile [REMOVED]
SSLCertificateKeyFile [REMOVED]
SSLCertificateChainFile [REMOVED]
SetEnvIf User-Agent ".*MSIE.*" \
         nokeepalive ssl-unclean-shutdown \
         downgrade-1.0 force-response-1.0
CustomLog logs/ssl_request_log \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

#Proxy
    DocumentRoot [REMOVED]

    ProxyPreserveHost On
    ProxyRequests Off

    ProxyPass [REMOVED] http://localhost:8081/[REMOVED]
    ProxyPassReverse [REMOVED] http://localhost:8081/[REMOVED]

    ProxyPassReverseCookiePath [REMOVED] /

    Alias [REMOVED] [REMOVED]

</VirtualHost>

Any clue? Thanks!

Upvotes: 3

Views: 1609

Answers (1)

Kornel
Kornel

Reputation: 100110

The headers are fine. Cache-Control: public and future Expires should do the job.

It seems like it's the browser's decision not to store the cache permanently (that kind of paranoia about HTTPS data is typical), and I don't think you can do anything about that.

Upvotes: 2

Related Questions