如何清除 Chrome 扩展程序后台进程的缓存?
我一般会看到几个有关清除 Chrome 缓存的问题,但这是特定于我使用后台脚本的扩展程序的。我有一个从后台脚本检索 Json 数据的扩展:
//In the content script
chrome.runtime.sendMessage({ query: 'getList' }, function (result) {
//Uses list data
});
在后台 js 文件内,我从 JQuery ajax 调用检索数据:
//In a background script
chrome.runtime.onMessage.addListener(
function (request, sender, sendResponse) {
$.get('http://example.com/data.txt', function (result) {
sendResponse(result);
});
});
我已经更新了服务器上 data.txt 文件的上下文。但是,Chrome 扩展程序继续使用旧数据。我在 Firefox 插件中运行了完全相同的代码,在 Firefox 中,我在更新 .txt 文件时立即看到新数据。
我不知道如何判断实际问题是否是 sendMessage() 调用只是使用缓存值而不是转到我的后台脚本,或者我的后台脚本是否只是返回缓存值而不是从中检索更新我的服务器。
我一天前更新了 .txt 文件,因此这不仅仅是短期缓存问题。我该怎么做才能强制 Chrome 扩展本身刷新来自后台脚本的数据?这似乎不是本地问题;即使卸载并重新安装脚本也无法解决问题;并不是说它被缓存在我的本地 Chrome 缓存中。
如果我在 Chrome(或任何浏览器)中访问 http://example.com/data.txt,我看到更新的文件。
我猜如果我将一个新包部署到 Chrome 开发人员仪表板,那么它就会清除。但我拥有此后台脚本和 JQuery 调用的全部原因是,我可以轻松更新此数据,而无需在扩展发生更改时重新部署扩展。
Chrome 开发者仪表板可以强制刷新吗?
I see several questions about clearing cache in Chrome in general, but this is specific to my extension which uses a background script. I have an extension which retrieves Json data from a background script:
//In the content script
chrome.runtime.sendMessage({ query: 'getList' }, function (result) {
//Uses list data
});
Inside the background js file, I'm retrieve data from a JQuery ajax call:
//In a background script
chrome.runtime.onMessage.addListener(
function (request, sender, sendResponse) {
$.get('http://example.com/data.txt', function (result) {
sendResponse(result);
});
});
I have updated the context of the data.txt file on my server. However, the Chrome extension continues to use the old data. I have the same exact code running in a Firefox add-on, and in Firefox I see the new data immediately when updating the .txt file.
I don't know how to tell whether the actual issue is that the sendMessage() call is just using a cached value instead of going to my background script, or whether my background script is just returning a cached value instead of retrieving the update from my server.
I updated the .txt file over a day ago, so it's not just a short-term caching issue. What can I do to force the Chrome extension itself to refresh the data coming from the background script? It does not appear to be a local issue; even uninstalling and re-installing the script doesn't fix the issue; it's not that it's being cached in my local Chrome cache.
If I visit http://example.com/data.txt in Chrome (or any browser), I see the updated file.
I'm guessing that if I deployed a new package to the Chrome Developer Dashboard, then it would clear. But the whole reason I have this background script and JQuery call is so that I can easily update this data without having to re-deploy the extension whenever it changes.
Is there anything that can be done from the Chrome Developer Dashboard to force it to refresh?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论