如何防止 Apache httpd (MAMP) 中的 http 文件缓存 [英] How to prevent http file caching in Apache httpd (MAMP)

查看:37
本文介绍了如何防止 Apache httpd (MAMP) 中的 http 文件缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 MAMP 中开发单页 Javascript 应用程序.我的 JavaScript 和 HTML 模板文件在请求之间被缓存.

是否有一种简单的方法可以在 MAMP 中指示我想阻止 http 文件缓存?可能带有 .htaccess 文件?我在哪里放置 .htaccess 或修改 Mac 上 MAMP 的虚拟主机?

解决方案

试过这个了吗?应该在 .htaccesshttpd.confVirtualHost(通常放在 httpd-vhosts.conf 中)> 如果你已经从你的 httpd.conf 中包含了它)

<块引用>

100% 防止文件被缓存

这类似于谷歌广告如何使用标头 Cache-Control: private, x-gzip-ok="";>防止代理和客户端缓存广告.

来自 http://www.askapache.com/htaccess/using-http-headers-with-htaccess.html

如果您使用的是 .html 以外的扩展名,还可以选择为正在检索的模板文件添加扩展名.

I am developing a single page Javascript application in MAMP. My JavaScript and HTML template files are getting cached between requests.

Is there a simple way to indicate in MAMP that I want to prevent http file caching? Possibly with a .htaccess file? Where do I place the .htaccess or modify the virtual host for MAMP on Mac?

解决方案

Tried this? Should work in both .htaccess, httpd.conf and in a VirtualHost (usually placed in httpd-vhosts.conf if you have included it from your 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.

From http://www.askapache.com/htaccess/using-http-headers-with-htaccess.html

And optionally add the extension for the template files you are retrieving if you are using an extension other than .html for those.

这篇关于如何防止 Apache httpd (MAMP) 中的 http 文件缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆