How to prevent caching resources in chrome extension?

When using "Download Unpacked Extension". I need to pass a query string (e.g.? V = \ d +) to scripts included on the original page in order to break the cache.

Is there a way to disable this caching behavior?

+6
source share
1 answer

Perhaps try to save the file with the update number, and when your users open the extension, it will detect a new update and clear the cache? You can add cache permission to the expansion manifest, as shown below:

"permissions": [ "browsingData", ], 

Then, in your extension, clear the cache as follows:

 var callback = function () { // Do something clever here once data has been removed. }; var millisecondsPerWeek = 1000 * 60 * 60 * 24 * 7; var oneWeekAgo = (new Date()).getTime() - millisecondsPerWeek; chrome.browsingData.remove({ "since": oneWeekAgo }, { "appcache": true, "cache": true, "cookies": true, "downloads": true, "fileSystems": true, "formData": true, "history": true, "indexedDB": true, "localStorage": true, "pluginData": true, "passwords": true, "webSQL": true }, callback); 
0
source

Source: https://habr.com/ru/post/921493/


All Articles