我正在 MAMP 中开发一个单页 Javascript 应用程序。我的 JavaScript 和 HTML 模板文件在请求之间被缓存。
是否有一种简单的方法可以在 MAMP 中指示我想要阻止 http 文件缓存?可能带有 .htaccess
文件?在 Mac 上,我应该在哪里放置 .htaccess
或修改 MAMP 的虚拟主机?
最佳答案
尝试过这个吗?应该在 .htaccess
、httpd.conf
和 VirtualHost
中工作(通常放置在 httpd-vhosts.conf
中) > 如果您已将其包含在 httpd.conf 中)
<filesMatch "\.(html|htm|js|css)$">
FileETag None
<ifModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</ifModule>
</filesMatch>
100% Prevent Files from being cached
This is similar to how google ads employ the header Cache-Control: private, x-gzip-ok="" > to prevent caching of ads by proxies and clients.
来自http://www.askapache.com/htaccess/using-http-headers-with-htaccess.html
如果您使用 .html
以外的扩展名,还可以选择为您要检索的模板文件添加扩展名。
关于apache - 如何防止 Apache httpd (MAMP) 中的 http 文件缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11532636/