Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Romain Courteaud
erp5
Commits
f5f14565
Commit
f5f14565
authored
Jun 08, 2019
by
Yusei Tahara
Committed by
Romain Courteaud
Feb 28, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[erp5_web_renderjs_ui] Update service worker code. Use lower case for non-global variables.
parent
251fe494
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
30 deletions
+30
-30
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_serviceworker.js
...lateItem/web_page_module/rjs_gadget_erp5_serviceworker.js
+28
-28
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_serviceworker.xml
...ateItem/web_page_module/rjs_gadget_erp5_serviceworker.xml
+2
-2
No files found.
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_serviceworker.js
View file @
f5f14565
...
...
@@ -243,13 +243,13 @@
client_id
=
event
.
clientId
.
toString
(),
// CACHE_MAP is a temprary data store.
// This should be kept until service worker stops.
CACHE_KEY
=
CACHE_MAP
[
client_id
],
ERP5JS_CACHE
;
cache_key
=
CACHE_MAP
[
client_id
],
erp5js_cache
;
url
.
hash
=
''
;
console
.
log
(
"
Client Id =
"
+
client_id
);
if
(
CACHE_KEY
)
{
console
.
log
(
"
CACHE_KEY from CACHE_MAP
"
+
CACHE_KEY
);
if
(
cache_key
)
{
console
.
log
(
"
cache_key from CACHE_MAP
"
+
cache_key
);
}
if
(
!
client_id
)
{
...
...
@@ -257,9 +257,9 @@
// use the CACHE_NAME that is defined in this service worker.
// It means that even if there is a new Cache, but web browser
// uses the Cache that was installed by this service worker.
CACHE_KEY
=
CACHE_NAME
;
CACHE_MAP
[
client_id
]
=
CACHE_KEY
;
console
.
log
(
"
CACHE_KEY from Service Worker
"
+
CACHE_KEY
);
cache_key
=
CACHE_NAME
;
CACHE_MAP
[
client_id
]
=
cache_key
;
console
.
log
(
"
cache_key from Service Worker
"
+
cache_key
);
}
if
((
event
.
request
.
method
!==
'
GET
'
)
||
(
required_url_list
.
indexOf
(
url
.
toString
())
===
-
1
))
{
...
...
@@ -270,50 +270,50 @@
return
event
.
respondWith
(
Promise
.
resolve
()
.
then
(
function
()
{
if
(
!
CACHE_KEY
)
{
// CLIENT_CACHE_MAPPING_NAME stores
CACHE_KEY
of each client.
if
(
!
cache_key
)
{
// CLIENT_CACHE_MAPPING_NAME stores
cache_key
of each client.
return
caches
.
open
(
CLIENT_CACHE_MAPPING_NAME
)
.
then
(
function
(
erp5js_
cache
)
{
.
then
(
function
(
cache
)
{
// Service worker forget everything when it stops. So, when it started
// again, CACHE_MAP is empty, get the associated
CACHE_KEY
from the
// again, CACHE_MAP is empty, get the associated
cache_key
from the
// special Cache named CLIENT_CACHE_MAPPING_NAME.
ERP5JS_CACHE
=
erp5js_
cache
;
erp5js_cache
=
cache
;
return
erp5js_cache
.
match
(
client_id
)
.
then
(
function
(
response
)
{
if
(
response
)
{
// We use Cache Storage as a persistent database.
CACHE_KEY
=
response
.
statusText
;
CACHE_MAP
[
client_id
]
=
CACHE_KEY
;
console
.
log
(
"
CACHE_KEY from Cache Storage
"
+
CACHE_KEY
);
cache_key
=
response
.
statusText
;
CACHE_MAP
[
client_id
]
=
cache_key
;
console
.
log
(
"
cache_key from Cache Storage
"
+
cache_key
);
}
})
})
})
;
})
;
}
})
.
then
(
function
()
{
if
(
!
CACHE_KEY
)
{
// If associated
CACHE_KEY
is not found, it means this client is a new one.
if
(
!
cache_key
)
{
// If associated
cache_key
is not found, it means this client is a new one.
// Let's find the latest Cache.
return
caches
.
keys
()
.
then
(
function
(
keys
)
{
keys
=
keys
.
filter
(
function
(
key
)
{
return
key
.
startsWith
(
prefix
);
});
console
.
log
(
"
KEYS =
"
+
keys
);
if
(
keys
.
length
)
{
CACHE_KEY
=
keys
.
sort
().
reverse
()[
0
];
CACHE_MAP
[
client_id
]
=
CACHE_KEY
;
cache_key
=
keys
.
sort
().
reverse
()[
0
];
CACHE_MAP
[
client_id
]
=
cache_key
;
}
else
{
CACHE_KEY
=
CACHE_NAME
;
cache_key
=
CACHE_NAME
;
CACHE_MAP
[
client_id
]
=
CACHE_NAME
;
}
// Save the associated
CACHE_KEY
in a persistent database because service
// Save the associated
cache_key
in a persistent database because service
// worker forget everything when it stops.
ERP5JS_CACHE
.
put
(
client_id
,
new
Response
(
null
,
{
"
statusText
"
:
CACHE_KEY
}));
})
erp5js_cache
.
put
(
client_id
,
new
Response
(
null
,
{
"
statusText
"
:
cache_key
}));
})
;
}
})
.
then
(
function
()
{
// Finally we have the associated
CACHE_KEY
. Let's find a cached response.
return
caches
.
open
(
CACHE_KEY
);
// Finally we have the associated
cache_key
. Let's find a cached response.
return
caches
.
open
(
cache_key
);
})
.
then
(
function
(
cache
)
{
// Don't give request object itself. Firefox's Cache Storage
...
...
@@ -328,7 +328,7 @@
}
// Not in cache - return the result from the live server
// `fetch` is essentially a "fallback"
console
.
log
(
"
MISS
"
+
CACHE_KEY
+
"
"
+
url
);
console
.
log
(
"
MISS
"
+
cache_key
+
"
"
+
url
);
return
fetch
(
event
.
request
);
})
);
...
...
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_serviceworker.xml
View file @
f5f14565
...
...
@@ -228,7 +228,7 @@
</item>
<item>
<key>
<string>
serial
</string>
</key>
<value>
<string>
976.15
605.32654.49476
</string>
</value>
<value>
<string>
976.15
722.43793.37154
</string>
</value>
</item>
<item>
<key>
<string>
state
</string>
</key>
...
...
@@ -246,7 +246,7 @@
</tuple>
<state>
<tuple>
<float>
15599
24528.42
</float>
<float>
15599
31548.14
</float>
<string>
UTC
</string>
</tuple>
</state>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment