简体   繁体   English

如何在Firefox上关闭缓存?

[英]How to turn off caching on Firefox?

During development I have to "clear cache" in Firefox all the time in order to make it use the latest version of JavaScript files. 在开发过程中,我必须始终在Firefox中“清除缓存”,以使其使用最新版本的JavaScript文件。

Is there some kind of setting (about:config) to turn off caching completely for JavaScript files? 是否有某种设置(about:config)完全关闭JavaScript文件的缓存? Or, if not, for all files? 或者,如果没有,对于所有文件?

Enter "about:config" into the Firefox address bar and set: 在Firefox地址栏中输入“about:config”并设置:

browser.cache.disk.enable = false
browser.cache.memory.enable = false

If developing locally, or using HTML5's new manifest attribute you may have to also set the following in about:config - 如果在本地开发,或使用HTML5的新清单属性,您可能还需要在about:config中设置以下内容:

browser.cache.offline.enable = false

Web Developer Toolbar可以选择禁用缓存,这样可以在需要时轻松打开和关闭缓存。

您是否尝试使用CTRL - F5更新页面?

There is no specific option to disable caching only for JavaScript, you will have to disable caching entirely. 没有特定的选项来禁用JavaScript的缓存,您必须完全禁用缓存。

FireBug has an option to disable the browser cache on the Network tab's drop down menu. FireBug可以选择在“网络”选项卡的下拉菜单中禁用浏览器缓存。

On the same page you want to disable the caching do this : FYI: the version am working on is 30.0 在同一页面上,您要禁用缓存执行此操作:仅供参考:我正在处理的版本是30.0

You can : 您可以 :

打开webdeveloper工具栏开放web开发人员

并选择禁用缓存

After that it will reload page from its own (you are on) and every thing is recached and any furthure request are recahed every time too and you may keep the web developer open always to keep an eye and make sure its always on (check). 在那之后它将从它自己重新加载页面(你在上)并且每一件事都被记录下来并且每次都会重新发送任何信息请求并且你可以保持web开发人员始终保持开放以便始终保持关注并确保它始终打开(检查) 。

If you're working with server side code you could generate a random number and append it to the end of the src in the following manner.... 如果您正在使用服务器端代码,您可以生成一个随机数,并以下列方式将其附加到src的末尾....

src="yourJavascriptFile.js?randomNumber=434534" SRC = “yourJavascriptFile.js?randomNumber = 434534”

with the randomNumber being randomly generated each time. 每次随机生成randomNumber。

Firefox 48 Developer Tools Firefox 48开发人员工具

Allows you to turn off cache only when toolbox is open, which is perfect for web development: 允许您仅在工具箱打开时关闭缓存,这非常适合Web开发:

  • F12 F12
  • gearbox on right upper corner 右上角的变速箱
  • scroll down top Advanced settings 向下滚动顶部高级设置
  • check "Disable Cache (when toolbox is open)" 选中“禁用缓存(工具箱打开时)”

在此输入图像描述

https://stackoverflow.com/a/27397425/895245 has similar content, but positioning changed a bit since. https://stackoverflow.com/a/27397425/895245有类似的内容,但定位有点改变了。

I know I'm resurrecting an ancient question, but I was trying to solve this problem today and have an alternate solution. 我知道我正在复活一个古老的问题,但我今天试图解决这个问题,并有一个替代解决方案。 Toggling caching when I want to test was not really acceptable for me, and as others mentioned, hard refreshing (ctrl+shift+r) doesn't always work. 我想测试时切换缓存对我来说并不是真的可以接受,正如其他人提到的那样,硬刷新(ctrl + shift + r)并不总是有效。

Instead, I opted to put the following in my vhost.conf file (can also be done in .htaccess) on my dev environment: 相反,我选择在我的开发环境中将以下内容放在我的vhost.conf文件中(也可以在.htaccess中完成):

<FilesMatch "\.(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>

On my dev environment, this ensures that js and css are always retrieved. 在我的开发环境中,这确保始终检索js和css。 Additionally it doesn't affect the rest of my browsing, and it also works for all browsers, so testing in chrome / ie etc is also easy. 此外,它不会影响我的其余浏览,它也适用于所有浏览器,因此在chrome / ie等测试也很容易。

Found the snippet here, some other handy apache tricks as well: http://www.askapache.com/htaccess/using-http-headers-with-htaccess.html#prevent-caching-with-htaccess 在这里找到了片段,其他一些方便的apache技巧: http//www.askapache.com/htaccess/using-http-headers-with-htaccess.html#prevent-caching-with-htaccess

To make sure that my clients always see the latest version on production, we increment the query string on the js include on each update, ie 为了确保我的客户始终在生产中看到最新版本,我们在每次更新的js include上增加查询字符串,即

jquery.somefile.js?v=0.5

This forces my clients' browsers to update their local cache when they see a new querystring, but then caches the new copy until the file is updated again 这会强制我的客户端浏览器在看到新的查询字符串时更新其本地缓存,但随后会缓存新副本,直到文件再次更新为止

You can use CTRL - F5 to reload bypassing the cache. 您可以使用CTRL - F5重新加载绕过缓存。

You can set the preferences in firefox not to use the cache 您可以在firefox中设置首选项以不使用缓存

network.http.use-cache = false

You can setup you web server to send a no-cache/Expires/Cache-Control headers for the js files. 您可以设置Web服务器以发送js文件的no-cache / Expires / Cache-Control标头。

Here is an example for apache web server. 以下是apache Web服务器的示例

Best strategy is to design your site to build a unique URL to your JS files, that gets reset every time there is a change. 最佳策略是设计您的站点以构建JS文件的唯一URL,每次发生更改时都会重置。 That way it caches when there has been no change, but imediately reloads when any change occurs. 这样它就会在没有变化时缓存,但在发生任何变化时立即重新加载。

You'd need to adjust for your specific environment tools, but if you are using PHP/Apache, here's a great solution for both you, and the end-users. 您需要针对特定​​的环境工具进行调整,但如果您使用的是PHP / Apache,这对您和最终用户来说都是一个很好的解决方案。

http://verens.com/archives/2008/04/09/javascript-cache-problem-solved/ http://verens.com/archives/2008/04/09/javascript-cache-problem-solved/

If you use FireBug, on the Network tab's drop down menu there is an option do disable the browser's cache. 如果您使用FireBug,在网络选项卡的下拉菜单中有一个选项可以禁用浏览器的缓存。

在此输入图像描述

In higher versions of Firefox, like Nightly, there is an options named "disable cache", you can find it by clicking the gear. 在较高版本的Firefox中,如Nightly,有一个名为“禁用缓存”的选项,您可以通过单击齿轮找到它。 And that options works only in current session, which means when you close inspector and restart it, you have to check it again if you want catch disabled. 并且该选项仅适用于当前会话,这意味着当您关闭检查器并重新启动它时,如果要禁用catch,则必须再次检查它。

I use CTRL - SHIFT - DELETE which activates the privacy feature, allowing you to clear your cache, reset cookies, etc, all at once. 我使用CTRL - SHIFT - DELETE激活隐私功能,允许您一次清除缓存,重置cookie等。 You can even configure it so that it just DOES it, instead of popping up a dialog box asking you to confirm. 您甚至可以对其进行配置,而不是弹出一个要求您确认的对话框。

There are pros and cons to the last two solutions posted, but they're both IMHO great solutions. 发布的最后两个解决方案有利有弊,但它们都是恕我直言的绝佳解决方案。

  1. You may or may not want your session ID embedded in your url like that for tighter security. 您可能希望也可能不希望将您的会话ID嵌入到您的网址中,以获得更严格的安全性。 But in development that shouldn't matter, but what if you forget to remove it? 但是在开发中这应该不重要,但是如果你忘记删除呢? Also does that really work? 这真的有用吗? Wouldn't you need something like a sequential number generator (hit count stored in the session, or maybe even just if 1 then 0, if 0 then 1)? 难道你不需要像序列号生成器这样的东西(在会话中存储命中计数,或者甚至只有1然后0,如果0然后1)?

  2. Adding a session id (or whatever sequencer) means you need to remember to add it to every resource you don't want cached. 添加会话ID(或任何序列器)意味着您需要记住将其添加到您不希望缓存的每个资源。 On the one hand that's better because you can just include your session id with just that resource you're actively developing and testing. 一方面,这是更好的,因为您可以只包含您正在积极开发和测试的资源的会话ID。 On the other hand, it means you have to do that and you have to remember to remove that for production. 另一方面,这意味着你必须这样做,你必须记住删除它用于生产。

  3. Modifying the vhost.conf or the .htaccess file does the trick nicely without the need to remember to add and remove the session id. 修改vhost.conf或.htaccess文件很有效,无需记住添加和删除会话ID。 But the downside is performance of all js and css resources will be affected, and if you have large files, that's going to slow you down. 但缺点是所有js和css资源的性能都会受到影响,如果你有大文件,这会降低你的速度。

Both seem like great, elegant solutions -- depends on your needs. 两者看起来都很棒,优雅的解决方案 - 取决于您的需求。

In firefox 45, disk cache options can be set by changing the value of: browser.cache.disk.enable 在firefox 45中,可以通过更改以下值来设置磁盘缓存选项:browser.cache.disk.enable

The value can be set on the "about:config" page. 该值可以在“about:config”页面上设置。

On http://kb.mozillazine.org/About:config_entries#Browser I found the following description for "browser.cache.disk.enable": http://kb.mozillazine.org/About:config_entries#Browser上,我找到了“browser.cache.disk.enable”的以下描述:

True (default): Use disk cache, up to capacity specified in browser.cache.disk.capacity False: Disable disk cache (same effect as setting browser.cache.disk.capacity to 0) True(默认值):使用磁盘缓存,最大为browser.cache.disk.capacity中指定的容量False:禁用磁盘缓存(与将browser.cache.disk.capacity设置为0的效果相同)

First of All, this can be easily done, for eg by PHP to force the browser to renew files based on cache date (expiration time). 首先,这可以很容易地完成,例如通过PHP强制浏览器根据缓存日期(到期时间)更新文件。 If you just need it for experimental needs, then try to use ctrl+shift+del to clear all cache at once inside Firefox browser. 如果您只是需要它来满足实验需求,那么尝试使用ctrl + shift + del在Firefox浏览器中立即清除所有缓存。 The third solution is to use many add-ons that exits for Firefox to clear cache based on time lines. 第三种解决方案是使用许多插件来退出Firefox以根据时间线清除缓存。

After 2 hours of browsing for various alternatives, this is something that worked for me. 经过2个小时的浏览以寻找各种替代方案,这对我有用。

My requirement was disabling caching of js and css files in my spring secured web application. 我的要求是在我的spring安全Web应用程序中禁用缓存js和css文件。 But at the same time caching these files "within" a particular session. 但同时在特定会话中“缓存”这些文件。

Passing a unique id with every request is one of the advised approaches. 在每个请求中传递唯一ID是建议的方法之一。

And this is what I did :- Instead of 这就是我所做的: - 而不是

<script language="javascript" src="js/home.js"></script>

I used 我用了

<script language="javascript" src="js/home.js?id=${pageContext.session.id}"></script>

Any cons to the above approach are welcome. 欢迎任何上述方法的缺点。 Security Issues ? 安全问题 ?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM