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
731e6160
Commit
731e6160
authored
Jun 07, 2019
by
Yusei Tahara
Committed by
Romain Courteaud
Feb 27, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[erp5_web_renderjs_ui] Add more comments because service worker is unstable and hard to use safely.
parent
4493f9c6
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
2 deletions
+24
-2
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_serviceworker.js
...lateItem/web_page_module/rjs_gadget_erp5_serviceworker.js
+22
-0
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 @
731e6160
...
...
@@ -168,6 +168,12 @@
self
.
addEventListener
(
'
install
'
,
function
(
event
)
{
// Perform install step: loading each required file into cache
event
.
waitUntil
(
// We create cache only if it does not exist. That is because
// we do not want to override an existing cache by mistake.
// Code consistency is very important. We must not mix different
// versions of code.
// (For example, developer change service worker code and forget
// to increase the cache version.)
caches
.
has
(
CACHE_NAME
)
.
then
(
function
(
result
)
{
if
(
!
result
)
{
...
...
@@ -192,6 +198,17 @@
.
then
(
function
(
keys
)
{
keys
=
keys
.
filter
(
function
(
key
)
{
return
key
.
startsWith
(
prefix
);
});
if
(
keys
.
length
===
1
)
{
// When user accesses ERP5JS web site first time, service worker is
// installed but it is not activated yet, service worker is activated
// when the page is refreshed or when a new tab opens the site again.
// If user does not refresh the page and continue to use the site,
// user can't use cache, so everything becomes slow. We must avoid this
// situation.
// So, we want to activate the new service worker immediately if it was
// the first one. (We must not activate the new service worker by
// skipWaiting if there is already an active service worker because it
// causes code inconsistency by loading code from a different version of
// cache.
// If there is only one cache, it means that this is the first service worker,
// thus we can do skipWaiting. And self.registration is unreliable on
// Firefox, we can't use self.registration.active
...
...
@@ -199,6 +216,8 @@
}
})
.
catch
(
function
()
{
// Since we do not allow to override existing cache, if cache installation
// failed, we need to delete the cache completely.
caches
.
delete
(
CACHE_NAME
);
throw
"
Download failed! Deleted
"
+
CACHE_NAME
;
});
...
...
@@ -348,6 +367,9 @@
);
})
.
then
(
function
()
{
// If new service worker becomes active, it means that all clients
// (tabs, windows, etc) were already closed. Thus we can remove the
// client cache mapping.
caches
.
delete
(
CLIENT_CACHE_MAPPING_NAME
);
})
);
...
...
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_serviceworker.xml
View file @
731e6160
...
...
@@ -228,7 +228,7 @@
</item>
<item>
<key>
<string>
serial
</string>
</key>
<value>
<string>
976.15
165.53290.29832
</string>
</value>
<value>
<string>
976.15
237.62291.34798
</string>
</value>
</item>
<item>
<key>
<string>
state
</string>
</key>
...
...
@@ -246,7 +246,7 @@
</tuple>
<state>
<tuple>
<float>
1559
898683.77
</float>
<float>
1559
902712.53
</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