.htacces AJAX 请求的缓存控制
我的网站上有一个页面,当用户单击按钮时发出 AJAX GET 请求,例如要获取的 url 如下所示:
/php/getData.php?field1=val1&field2=val2
getData.php
返回的值与这两个值将不会更改(至少几个月)那么如何在 .htaccess 文件中实现缓存控制以告诉浏览器将结果缓存一段时间?
例如,我告诉浏览器通过以下方式缓存 js 和 css 文件:
<FilesMatch "\.(css|js)$">
Header set Cache-Control "max-age=3024000, must-revalidate"
</FilesMatch>
^ 这将缓存控制标头设置为 30 天。
任何帮助将不胜感激。
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,Apache 中没有指令来匹配查询字符串。只是文件名和目录。
Unfortunately, there is no directive in Apache to match against a query-string. Just filenames and directories.