Forum Moderators: phranque

Message Too Old, No Replies

Disabling all caching for one virtualhost?

         

l008comm

11:00 am on May 15, 2019 (gmt 0)

10+ Year Member Top Contributors Of The Month



I use the following code for my global server caching settings. It works very well. Note that I don't cache html at all, as all my pages are dynamic content. But I do cache CSS and Javascript, and all typical content like images, audio and video.
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault A0
ExpiresByType text/css "access 1 days"
ExpiresByType text/plain "access 1 days"
ExpiresByType text/javascript "access 1 days"
ExpiresByType application/javascript "access 1 days"
ExpiresByType image/bmp "access 7 days"
ExpiresByType image/gif "access 7 days"
ExpiresByType image/ief "access 7 days"
ExpiresByType image/jpeg "access 7 days"
ExpiresByType image/png "access 7 days"
ExpiresByType image/tiff "access 7 days"
ExpiresByType image/svg "access 7 days"
ExpiresByType image/svg+xml "access 7 days"
ExpiresByType audio/basic "access 2 weeks"
ExpiresByType audio/midi "access 2 weeks"
ExpiresByType audio/mpeg "access 2 weeks"
ExpiresByType application/ogg "access 2 weeks"
ExpiresByType video/mpeg "access 2 weeks"
</IfModule>


Now I'm working on a new mobile site for one of my websites, and it runs on it's own subdomain. Turns out it is really difficult to force-reload a page in most phones and even some desktop browsers. So what I want to do is turn off ALL caching one one virtual host until the site is ready to go live. I haven't found docs that clearly indicate how to do this. The official docs do say that ExpiresActive and ExpiresDefault can be used in virtualhosts, so I stuck the following in my virtualhost container for this one subdomain, but it didn't have any effect:


# no caching for this domain during web development
ExpiresActive On
ExpiresDefault A0


Any thoughts? It is TORTURE trying to do mobile web development, fighting cached files on every device.

l008comm

11:15 am on May 15, 2019 (gmt 0)

10+ Year Member Top Contributors Of The Month



I also tried the following in my virtualhost container:

ExpiresActive Off


Even after a real hard reload, it's still caching things. I think I need to explicitly tell it no somehow. If I explicitly give it a 'no-cache' header, how is that going to coexist with the default 'Expires' headers that mod_expires is sending?

phranque

11:42 am on May 15, 2019 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



I also tried the following in my virtualhost container:

ExpiresActive Off

this should have worked:
This directive enables or disables the generation of the Expires and Cache-Control headers for the document realm in question.

source: https://httpd.apache.org/docs/current/mod/mod_expires.html#expiresactive

If I explicitly give it a 'no-cache' header, how is that going to coexist with the default 'Expires' headers that mod_expires is sending?

you need an Expires header to prevent mod_expires from generating its own:
When the Expires header is already part of the response generated by the server, for example when generated by a CGI script or proxied from an origin server, this module does not change or add an Expires or Cache-Control header.

source: https://httpd.apache.org/docs/current/mod/mod_expires.html#expiresactive

so you can generate an "already expired" Expires header using mod_header:
HTTP/1.1 clients and caches MUST treat other invalid date formats, especially including the value "0", as in the past (i.e., "already expired").

To mark a response as "already expired," an origin server sends an Expires date that is equal to the Date header value.

source: https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.21

whether this would actually work in your application depends on the order in which these modules run (i.e. mod_headers before mod_expires)