-
-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
$mol_offline refactor, disable cache on page reload via dev server #710
Open
zerkalica
wants to merge
65
commits into
master
Choose a base branch
from
offline2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 54 commits
Commits
Show all changes
65 commits
Select commit
Hold shift + click to select a range
b22b11a
$mol_offline refactor, disable cache on page reload via dev server
zerkalica 9d5f058
$mol_offline refactor
zerkalica ce606ba
$mol_offline refactor 2 - simplify respond
zerkalica ca3be5d
$mol_offline refactor 3 - simplify respond
zerkalica f965597
$mol_offline refactor 4 - extracted send
zerkalica 81a9ac6
$mol_offline refactor
zerkalica c83d213
$mol_offline mol_build_obsolete message pass to worker to disable cache
zerkalica 9f3722b
$mol_offline review fixes
zerkalica 84c0253
$mol_offline review fixes 2
zerkalica c476bb3
$mol_offline fixes 3
zerkalica f8eab6a
$mol_offline refactor, extract $mol_worker
zerkalica f17f33b
$mol_offline fix refresh
zerkalica 6efe454
$mol_offline use force-cache
zerkalica 5864255
$mol_offline rules refactored, some bugs fixed
zerkalica 201dcb2
$mol_offline configure cached and blocked urls regexp
zerkalica cd84bfa
$mol_offline fix regexp
zerkalica 958e207
$mol_worker_service plugins, refactor
zerkalica 2dcd5aa
$mol_offline save ignore_cache between window.reload()
zerkalica 08aa70c
$mol_offline fix test.html caching
zerkalica 3593a0a
$mol_worker refactor
zerkalica e25b677
$mol_worker fix worker singletone
zerkalica db14037
$mol_worker fix try/catch in attach
zerkalica bb46b57
$mol_worker_service renamed to $mol_service, $mol_offline refactor to…
zerkalica 121c90e
$mol_service fix init hook
zerkalica 9f86a71
$mol_service refactor extracted fetch service and notify
zerkalica 7d3ce8a
$mol_fetch_service fix bug with fetch_event binded scope
zerkalica b168b72
$mol_fetch_service refactor simplify add logic
zerkalica 354468b
$mol_service_plugin extracted, used static, fetch hook moved back to …
zerkalica 7a0cf1e
$mol_service refactor detach method, auto init
zerkalica d53c252
$mol_service_plugin namespace
zerkalica 21da91e
$mol_service_plugin remove plugin filter, simplify
zerkalica cbcef3f
$mol_service_plugin moved to $ namespace
zerkalica ea7d089
$mol_build_client removed unused postMessage
zerkalica 02d8dcc
$mol_service_plugin - include mol_service, add waitUntil to modify, $…
zerkalica 7f7ce8d
$mol_service fix inner namespace
zerkalica 4b10be0
$mol_service_host refactor, better update handling api
zerkalica d12f71f
$mol_service review fixes
zerkalica a202b1b
$mol_offline regexp to URL parser
zerkalica 61fb6db
$mol_service separate worker plugins, fixes
zerkalica 5b68802
$mol_service moved to wires, better errors
zerkalica 00dcb49
$mol_service refactor
zerkalica 33b1fc6
$mol_service refactor
zerkalica 3ee7e45
$mol_worker async
zerkalica 6fabdac
$mol_offline refactoring
zerkalica 10b0cef
$mol_service push event handler added, sync scope
zerkalica 1efed9b
$mol_service_worker refactor, extracted prompt events
zerkalica 7f008e6
$mol_service_worker type fix
zerkalica 2169769
$mol_service_worker simple notify
zerkalica 2265c73
$mol_service_prompt moved to offline, refactor
zerkalica 9dafc68
$mol_offline web
zerkalica 7778411
$mol_service_worker fix start
zerkalica a2aa4c3
$mol_offline fix prompt offline
zerkalica b13f25e
Merge branch 'master' of github.com:hyoo-ru/mam_mol into offline2
zerkalica 6715f91
$mol_service_worker minor fixes
zerkalica 001e562
$mol_fetch removed unused request
zerkalica 60811c1
$mol_service refactor, split self and worker
zerkalica d579f8a
$mol_service fixes
zerkalica 370372a
$mol_service fixes 2
zerkalica a33dcaf
$mol_worker rpc refactored
zerkalica 7849b8a
$mol_notify fixes
zerkalica 854046d
$mol_rpc_client fix call bug
zerkalica 667e459
Merge branch 'master' of github.com:hyoo-ru/mam_mol into offline2
zerkalica e995539
Merge branch 'master' of github.com:hyoo-ru/mam_mol into offline2
zerkalica 48fe3a1
$mol_offline add require-corp header
zerkalica 3cb5e0f
$mol_file_node fix error handler
zerkalica File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
namespace $ { | ||
|
||
export type $mol_notify_info = { | ||
context: string, | ||
message: string, | ||
uri: string | ||
} | ||
|
||
export class $mol_notify extends $mol_object { | ||
|
||
@ $mol_mem | ||
static allowed( next?: boolean ) { | ||
return false | ||
} | ||
|
||
static show( info: $mol_notify_info ) { | ||
this.$.$mol_service_worker.send(info) | ||
zerkalica marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
} | ||
|
||
export class $mol_notify_service extends $mol_service_plugin_notify { | ||
static override data(data: {}) { | ||
if ('uri' in data && 'message' in data) { | ||
this.show(data as $mol_notify_info) | ||
return true | ||
} | ||
return null | ||
} | ||
|
||
static show(info: $mol_notify_info) {} | ||
|
||
} | ||
|
||
export namespace $mol_service_plugin { | ||
export let $mol_notify_service = $.$mol_notify_service | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,3 @@ | ||
namespace $ { | ||
try { | ||
$mol_offline() | ||
} catch( error ) { | ||
console.error( error ) | ||
} | ||
$mol_offline | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,69 @@ | ||
namespace $ { | ||
|
||
export function $mol_offline( ) {} | ||
export class $mol_offline extends $mol_service_plugin_cache { | ||
static blocked_urls = [ | ||
'//cse.google.com/adsense/search/async-ads.js' | ||
] | ||
|
||
static override blocked( request: Request ) { | ||
const normalized_url = request.url.replace( /^https?:/, '' ) | ||
|
||
return this.blocked_urls.includes(normalized_url) | ||
} | ||
|
||
static override activate() { | ||
this.$.$mol_service_worker.claim() | ||
} | ||
|
||
static override need_modify(request: Request) { | ||
if( request.method !== 'GET' ) return false | ||
if( !/^https?:/.test( request.url ) ) return false | ||
if( /\?/.test( request.url ) ) return false | ||
if( request.cache === 'no-store' ) return false | ||
|
||
return true | ||
} | ||
|
||
static override modify(request: Request) { | ||
let fallback_header | ||
|
||
const html = request.mode === 'navigate' | ||
const cache = request.cache | ||
|
||
if (cache === 'reload' || ( cache === 'no-cache' && ! html ) ) { | ||
if (cache === 'reload') { | ||
// F5 + Disable cache | ||
request = new ($mol_wire_sync(Request))(request, { cache: 'no-cache' }) | ||
} | ||
|
||
// fetch with fallback to cache if statuses not match | ||
try { | ||
const actual = this.$.$mol_fetch.response(request) | ||
if (actual.code() < 400) return actual.native | ||
|
||
fallback_header = actual.message() | ||
} catch (err) { | ||
if ( $mol_promise_like(err) ) $mol_fail_hidden(err) | ||
fallback_header = (err as Error).message || 'Fetch error' | ||
} | ||
} | ||
|
||
if (cache !== 'force-cache') { | ||
request = new ($mol_wire_sync(Request))(request, { cache: 'force-cache' }) | ||
} | ||
|
||
const cached = this.$.$mol_fetch.response(request) | ||
|
||
if (! fallback_header ) return cached.native | ||
|
||
const clone = cached.clone() | ||
clone.headers().set( '$mol_offline_remote_status', `${fallback_header} $mol_offline fallback to cache`) | ||
|
||
return clone.native | ||
} | ||
} | ||
|
||
export namespace $mol_service_plugin { | ||
export let $mol_offline = $.$mol_offline | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Хотя, сделать и над реквестом обёртку возможно не плохая идея. Есть ил ещё какая полезная функциональность для реквестов помимо клонирования?