Skip to content

Commit

Permalink
$mol_offline save ignore_cache between window.reload()
Browse files Browse the repository at this point in the history
  • Loading branch information
zerkalica committed Oct 28, 2024
1 parent 958e207 commit 2dcd5aa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
12 changes: 10 additions & 2 deletions offline/offline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@ namespace $ {
constructor() {
super()
this.$.$mol_dom_context.addEventListener('message', e => {
if (e.data === 'mol_build_obsolete') this.value('ignore_cache', true)
if (e.data === 'mol_build_obsolete') this.ignore_cache(this.value('ignore_cache', true))
})
}

protected ignore_cache(next?: null | boolean) {
return this.$.$mol_state_session.value(`${this}.ignore_cache()`, next)
}

@ $mol_mem
override defaults() {
const ignore_cache = this.ignore_cache()
this.ignore_cache(null)

return {
ignore_cache: false,
ignore_cache: ignore_cache ?? false,
blocked_urls: [
'//cse.google.com/adsense/search/async-ads.js'
]
Expand Down
8 changes: 6 additions & 2 deletions offline/offline.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ namespace $ {
override fetch_event(event: FetchEvent) {
const request = event.request

if( this.value('blocked_urls')?.includes(request.url.replace( /^https?:/, '' )) ) {
const blocked_urls = this.value('blocked_urls')
const normalized_url = request.url.replace( /^https?:/, '' )

if( blocked_urls?.includes(normalized_url) ) {
event.respondWith(
new Response(
null,
Expand All @@ -31,8 +34,9 @@ namespace $ {

const force_cache = /.+\/[^\/]+\.html/.test(request.url)
const no_cache = request.cache === 'no-cache' && ! force_cache
const ignore_cache = this.value('ignore_cache')

if (this.value('ignore_cache') || request.cache === 'reload' || no_cache) {
if (ignore_cache || request.cache === 'reload' || no_cache) {

if (request.cache !== 'no-cache' && request.cache !== 'reload') {
request = new Request(request, { cache: 'no-cache' })
Expand Down
1 change: 0 additions & 1 deletion worker/service/worker.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ namespace $ {
return reg
}


static installing(reg: $mol_worker_service_reg_installing) {
reg.addEventListener( 'updatefound', this.update_found.bind(this, reg.installing))
}
Expand Down

0 comments on commit 2dcd5aa

Please sign in to comment.