Disable cache Chrome Extension

喜夏-厌秋 提交于 2020-01-24 09:30:28

问题


I made a plugin that loads a handful of pages of my game website, but I'd like it to also disable the cache as it loads. I can only find cache disabling during reloading. I could load the page, then reload it every time, but that seems not ideal. Is there some way I could disable the cache for my generated tabs, either by the tabs themselves or even the domain.


回答1:


What wOxxOm said is correct, using the webRequest API I could modify the cache-control headers. I needed to make a background script with this:

chrome.webRequest.onBeforeSendHeaders.addListener(
function (details) {
    var headers = details.requestHeaders || [];
    headers.push({
        "name": "Cache-Control",
        "value": "no-cache"
    });
    return {requestHeaders: headers};
},
{
    urls: [
        "*://test.domain.tv/*",
        "*://domain.tv/*"
    ]
},
[]
);

I also had to add "webRequest" to my manifest.



来源:https://stackoverflow.com/questions/45725712/disable-cache-chrome-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!