Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
mastofe
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Pleroma
mastofe
Commits
72123423
Commit
72123423
authored
7 years ago
by
Akihiko Odaki
Committed by
Eugen Rochko
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Synchronize HTML page cache with sessions (#6815)
parent
566ace2d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.babelrc
+2
-0
2 additions, 0 deletions
.babelrc
app/javascript/mastodon/service_worker/entry.js
+24
-6
24 additions, 6 deletions
app/javascript/mastodon/service_worker/entry.js
with
26 additions
and
6 deletions
.babelrc
+
2
−
0
View file @
72123423
...
...
@@ -4,6 +4,8 @@
[
"env",
{
"debug": true,
"exclude": ["transform-async-to-generator", "transform-regenerator"],
"loose": true,
"modules": false,
"targets": {
...
...
This diff is collapsed.
Click to expand it.
app/javascript/mastodon/service_worker/entry.js
+
24
−
6
View file @
72123423
import
'
./web_push_notifications
'
;
function
openCache
()
{
return
caches
.
open
(
'
mastodon-web
'
);
}
function
fetchRoot
()
{
return
fetch
(
'
/
'
,
{
credentials
:
'
include
'
});
}
...
...
@@ -7,10 +11,7 @@ function fetchRoot() {
// Cause a new version of a registered Service Worker to replace an existing one
// that is already installed, and replace the currently active worker on open pages.
self
.
addEventListener
(
'
install
'
,
function
(
event
)
{
const
promises
=
Promise
.
all
([
caches
.
open
(
'
mastodon-web
'
),
fetchRoot
()]);
const
asyncAdd
=
promises
.
then
(([
cache
,
root
])
=>
cache
.
put
(
'
/
'
,
root
));
event
.
waitUntil
(
asyncAdd
);
event
.
waitUntil
(
Promise
.
all
([
openCache
(),
fetchRoot
()]).
then
(([
cache
,
root
])
=>
cache
.
put
(
'
/
'
,
root
)));
});
self
.
addEventListener
(
'
activate
'
,
function
(
event
)
{
event
.
waitUntil
(
self
.
clients
.
claim
());
...
...
@@ -19,12 +20,29 @@ self.addEventListener('fetch', function(event) {
const
url
=
new
URL
(
event
.
request
.
url
);
if
(
url
.
pathname
.
startsWith
(
'
/web/
'
))
{
event
.
respondWith
(
fetchRoot
().
then
(
response
=>
{
const
asyncResponse
=
fetchRoot
();
const
asyncCache
=
openCache
();
event
.
respondWith
(
asyncResponse
.
then
(
async
response
=>
{
if
(
response
.
ok
)
{
return
response
;
const
cache
=
await
asyncCache
;
await
cache
.
put
(
'
/
'
,
response
);
return
response
.
clone
();
}
throw
null
;
}).
catch
(()
=>
caches
.
match
(
'
/
'
)));
}
else
if
(
url
.
pathname
===
'
/auth/sign_out
'
)
{
const
asyncResponse
=
fetch
(
event
.
request
);
const
asyncCache
=
openCache
();
event
.
respondWith
(
asyncResponse
.
then
(
async
response
=>
{
if
(
response
.
ok
||
response
.
type
===
'
opaqueredirect
'
)
{
const
cache
=
await
asyncCache
;
await
cache
.
delete
(
'
/
'
);
}
return
response
;
}));
}
});
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment