Skip to content

Commit

Permalink
Add ability to bypass browser cache when fetching a resource
Browse files Browse the repository at this point in the history
Related issue:
- uBlockOrigin/uBlock-issues#682 (comment)

The following advanced setting has been added:

    updateAssetBypassBrowserCache

Default to `false`. If set to `true`, uBO will ensure the
browser cache is bypassed when fetching a remote resource.

This is for the convenience of filter list maintainers who
may want to test the latest version of their lists when
fetched from their remote location.
  • Loading branch information
gorhill committed Jul 26, 2019
1 parent 8d136ec commit 048bfd2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/js/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,16 @@ api.fetchText = function(url, onLoad, onError) {
// https://github.com/gorhill/uBlock/issues/2592
// Force browser cache to be bypassed, but only for resources which have
// been fetched more than one hour ago.
//
// https://github.com/uBlockOrigin/uBlock-issues/issues/682#issuecomment-515197130
// Provide filter list authors a way to completely bypass
// the browser cache.
if ( isExternal ) {
const queryValue = `_=${Math.floor(Date.now() / 3600000) % 12}`;
const cacheBypassToken =
µBlock.hiddenSettings.updateAssetBypassBrowserCache
? Math.floor(Date.now() / 1000) % 86400
: Math.floor(Date.now() / 3600000) % 12;

This comment has been minimized.

Copy link
@gwarser

gwarser Mar 22, 2020

Contributor

@gorhill, I think this should be "modulo prime", not 12. If someone always turn on PC in "8am" there is a slight chance to hit cache.

And if PC is turned off before autoUpdatePeriod this will be even worse.

This comment has been minimized.

Copy link
@gorhill

gorhill Mar 22, 2020

Author Owner

I am pretty sure whatever is cached will be no longer valid after a full day -- for example GitHub says that the resource is to be cached for 300 seconds.

This comment has been minimized.

Copy link
@gorhill

gorhill Mar 22, 2020

Author Owner

Note I don't mind changing 12 for 13, it's trivial, a good idea which better implement the primary purpose, and a nothing-to-worry-about change. As there been a case where using 12 is an issue or it's just out of code review?

This comment has been minimized.

Copy link
@gwarser

gwarser Mar 22, 2020

Contributor

I just had this code in mind, and have seen one or two complains about filters not updating. Nothing specific.

GitHub says that the resource is to be cached for 300 seconds.

Ah, then it should be fine for most popular filters. I only see higher values in less active filters.

const queryValue = `_=${cacheBypassToken}`;
if ( actualUrl.indexOf('?') === -1 ) {
actualUrl += '?';
} else {
Expand Down
1 change: 1 addition & 0 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const µBlock = (function() { // jshint ignore:line
selfieAfter: 3,
strictBlockingBypassDuration: 120,
suspendTabsUntilReady: 'unset',
updateAssetBypassBrowserCache: false,
userResourcesLocation: 'unset',
};

Expand Down

0 comments on commit 048bfd2

Please sign in to comment.