Search code examples
ajaxapachecaching.htaccesscache-control

.htacces cache control for AJAX requests


I have a page on my website that makes AJAX GET requests when a user clicks a button, for example the url to be gotten will look like:

/php/getData.php?field1=val1&field2=val2

The value returned by getData.php with these two values will not change (at least for a few months) so how can I implement cache control in my .htaccess file to tell the browser to cache the result for a certain amount of time?

For example, I tell the browser to cache js and css file in the following way:

<FilesMatch "\.(css|js)$">
Header set Cache-Control "max-age=3024000, must-revalidate"
</FilesMatch>

^ this sets the cache-control header for 30 days.

Any help would be much appreciated.

Thanks


Solution

  • Unfortunately, there is no directive in Apache to match against a query-string. Just filenames and directories.