Welcome to WebmasterWorld Guest from 3.227.233.78

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

Http response headers not indicating browser caching why?

     
8:43 am on Aug 2, 2016 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:Dec 19, 2004
posts: 993
votes: 14


I've implemented browser caching on my Apache server site. Running Cloudflare.

However when I see the http response headers it shows following:

Cache-Control: max-age=0, no-cache

Does that indicate browser caching is off? Kindly assist Thanks!
9:51 am on Aug 2, 2016 (gmt 0)

Full Member

Top Contributors Of The Month

joined:Apr 11, 2015
posts: 328
votes: 24


How have you implemented "browser caching"? That Cache-Control header certainly suggests client-side caching is disabled, but we'd need to see the entire response headers. Have you created the appropriate page rules for CloudFlare to cache content?
11:44 am on Aug 2, 2016 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:Dec 19, 2004
posts: 993
votes: 14


I've implemented browser caching through .htaccess file. Btw I've stopped Cloudflare for now. What's wrong with my setup? Thanks!
12:00 pm on Aug 2, 2016 (gmt 0)

Full Member

Top Contributors Of The Month

joined:Apr 11, 2015
posts: 328
votes: 24


I've implemented browser caching through .htaccess file.


Are you using mod_expires, mod_headers, ...? We'd need to see the directives used and "the entire response headers" as sent from the server. Server-side code could also be overriding these headers. Cookies and other elements of the request could also be breaking the cache?
12:43 pm on Aug 2, 2016 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:Dec 19, 2004
posts: 993
votes: 14


Hi here is the htaccess code:

<IfModule mod_expires.c>
# Enable expirations.
ExpiresActive On

ExpiresByType text/css "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType application/x-javascript "access plus 1 month"
ExpiresByType text/js "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"

ExpiresDefault "access 1 month"

<FilesMatch \.php$>
ExpiresActive Off
</FilesMatch>
</IfModule>
1:27 pm on Aug 2, 2016 (gmt 0)

Full Member

Top Contributors Of The Month

joined:Apr 11, 2015
posts: 328
votes: 24


What resource are you testing and what are the full set of response headers?


ExpiresByType application/javascript "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType application/x-javascript "access plus 1 month"
ExpiresByType text/js "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"


Why so many JavaScript-type directives? Your server should only be responding with 1 mime-type here, so you only need 1 directive.

Is mod_expires enabled? Try removing the <IfModule> wrapper... any error?
1:38 pm on Aug 2, 2016 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:Dec 19, 2004
posts: 993
votes: 14


So what javascript directive you recommend? mod_expires is enabled. I checked via /usr/sbin/httpd -M

Here is the header response when I "fetch as google" in Google Webmaster tools:

====
HTTP/1.1 200 OK
Date: Tue, 02 Aug 2016 19:06:15 GMT
Server: Apache
X-Powered-By: PHP/5.3.29
ETag: "1c45ab3622cc8b173d24806379"
Expires: Sun, 19 Nov 1978 05:00:00 GMT
Cache-Control: must-revalidate
Set-Cookie: SESSef4017cc9c9b7497c98fadc=1bd21d699e1defe55ca46c4e90e25847; expires=Thu, 25-Aug-2016 22:39:35 GMT; path=/; domain=.xxx.com
X-Mod-Pagespeed: 1.11.33.2-0
Vary: Accept-Encoding
Content-Type: text/html; charset=utf-8
Cache-Control: max-age=0, no-cache
Content-Length: 170114
Connection: close
====
1:45 pm on Aug 2, 2016 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:Dec 19, 2004
posts: 993
votes: 14


I tried commenting <ifmodule> wrapper and the site work but fetch as google doesn't change at all.
2:36 pm on Aug 2, 2016 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:Dec 19, 2004
posts: 993
votes: 14


Where else should i check ? Btw I'm running Drupal cms
4:13 pm on Aug 2, 2016 (gmt 0)

Full Member

Top Contributors Of The Month

joined:Apr 11, 2015
posts: 328
votes: 24


So what javascript directive you recommend?


Whatever Content-Type your server responds with (probably "application/javascript", but you need to check the response headers when serving JS files).

What resource are you testing... ?


...when I "fetch as google" in Google Webmaster tools:


Ah, well that's kinda the "problem" - you aren't testing a static resource for which you have explicitly set up caching directives with mod_expires. You are testing the main page ("X-Powered-By: PHP/5.3.29" / "text/html") request. If this is a ".php" file then you've explicitly disabled caching with the above directives.

But this is probably intentional - it's difficult to cache dynamic PHP pages client-side. For a start, you are sending back cookies - as mentioned above, this can break the cache. Cookies are not going to work too well if the resource is cached client-side, since they probably need to be sent back on the next request.

ETag: "1c45ab3622cc8b173d24806379"


You already appear to be using a different caching mechanism for this resource... ETags. These are managed by the server.
4:20 pm on Aug 2, 2016 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:Dec 19, 2004
posts: 993
votes: 14


Yes you are quite right. The main page is .php file so it makes sense to disable it as per directives I added. Thanks so much for clearing up this issue for me!
9:23 pm on Aug 2, 2016 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:15889
votes: 876


I tried commenting <ifmodule> wrapper

That's fine. You don't need the wrapper anyway: either you have the mod or you don't. The effect of the wrapper is to tell the server "If suchandsuch mod is available, continue reading line by line; if it isn't, simply pretend you don't see the lines inside the wrapper". Most of the time, the stuff inside the wrapper will be directives belonging to whatever mod is involved in the wrapper-- but it doesn't have to be.

I thought CloudFlare basically overrides anything you've said about caching, because they maintain their own cache with their own rules. At least that's the impression you get from the content of a CloudFlare error page, if you've ever happened to see one. (Try anything in the notalwaysblahblah family at some peak-traffic hour.)