Commit 1d864fbf authored by Romain Courteaud's avatar Romain Courteaud

WIP [erp5_web_renderjs_ui] Replace appcache by a service worker

Fetch usage can be bypassed to do not use service worker when not needed.

As appcache has been dropped on Firefox, this change will improve the speed on Firefox.

No change is expected on Chrome/Safari.
parent fcdf2da4
/*jslint indent: 2*/
/*global self, caches, fetch*/
(function (self, caches, fetch) {
/*global self, caches, fetch, Promise, URL, location*/
(function (self, caches, fetch, Promise, URL, location) {
"use strict";
var CACHE_NAME = 'Thu, 12 July 2016 12:00:00 GMT',
var prefix = location.toString() + '_',
CACHE_NAME = prefix + 'Tue, 26 Mars 2019 12:00:00 GMT',
// Files required to make this app work offline
REQUIRED_FILES = [
'./',
'https://netdna.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css',
'https://netdna.bootstrapcdn.com/font-awesome/4.2.0/fonts/fontawesome-webfont.eot?v=4.2.0',
'https://netdna.bootstrapcdn.com/font-awesome/4.2.0/fonts/fontawesome-webfont.eot?#iefix&v=4.2.0',
'https://netdna.bootstrapcdn.com/font-awesome/4.2.0/fonts/fontawesome-webfont.woff?v=4.2.0',
'https://netdna.bootstrapcdn.com/font-awesome/4.2.0/fonts/fontawesome-webfont.ttf?v=4.2.0',
'https://netdna.bootstrapcdn.com/font-awesome/4.2.0/fonts/fontawesome-webfont.svg?v=4.2.0#fontawesomeregular',
'URI.js',
'erp5_launcher.js',
'gadget_erp5.css',
'favicon.ico',
'font-awesome/font-awesome-webfont.eot',
'font-awesome/font-awesome-webfont.woff',
'font-awesome/font-awesome-webfont.woff2',
'font-awesome/font-awesome-webfont.ttf',
'font-awesome/font-awesome-webfont.svg',
'gadget_erp5_worklist_empty.svg?format=svg',
'erp5_launcher_nojqm.js',
'gadget_erp5_nojqm.css',
'gadget_erp5_configure_editor.html',
'gadget_erp5_configure_editor.js',
'gadget_erp5_editor_panel.html',
'gadget_erp5_editor_panel.js',
'gadget_erp5_field_checkbox.html',
'gadget_erp5_field_checkbox.js',
'gadget_erp5_field_datetime.html',
'gadget_erp5_field_datetime.js',
'gadget_erp5_field_editor.html',
'gadget_erp5_field_editor.js',
'gadget_erp5_field_email.html',
'gadget_erp5_field_email.js',
'gadget_erp5_field_file.html',
'gadget_erp5_field_file.js',
'gadget_erp5_field_float.html',
'gadget_erp5_field_float.js',
'gadget_erp5_field_formbox.html',
'gadget_erp5_field_formbox.js',
'gadget_erp5_field_gadget.html',
'gadget_erp5_field_gadget.js',
'gadget_erp5_field_image.html',
......@@ -36,8 +42,12 @@
'gadget_erp5_field_integer.js',
'gadget_erp5_field_list.html',
'gadget_erp5_field_list.js',
'gadget_erp5_field_lines.html',
'gadget_erp5_field_lines.js',
'gadget_erp5_field_listbox.html',
'gadget_erp5_field_listbox.js',
'gadget_erp5_field_matrixbox.html',
'gadget_erp5_field_matrixbox.js',
'gadget_erp5_field_multicheckbox.html',
'gadget_erp5_field_multicheckbox.js',
'gadget_erp5_field_multilist.html',
......@@ -62,8 +72,14 @@
'gadget_erp5_header.js',
'gadget_erp5_jio.html',
'gadget_erp5_jio.js',
'gadget_erp5_label_field.html',
'gadget_erp5_label_field.js',
'gadget_erp5_notification.html',
'gadget_erp5_notification.js',
'gadget_erp5_page_action.html',
'gadget_erp5_page_action.js',
'gadget_erp5_page_export.html',
'gadget_erp5_page_export.js',
'gadget_erp5_page_form.html',
'gadget_erp5_page_form.js',
'gadget_erp5_page_front.html',
......@@ -72,6 +88,8 @@
'gadget_erp5_page_history.js',
'gadget_erp5_page_jump.html',
'gadget_erp5_page_jump.js',
'gadget_erp5_page_language.html',
'gadget_erp5_page_language.js',
'gadget_erp5_page_logout.html',
'gadget_erp5_page_logout.js',
'gadget_erp5_page_preference.html',
......@@ -86,6 +104,9 @@
'gadget_erp5_page_worklist.js',
'gadget_erp5_panel.html',
'gadget_erp5_panel.js',
'gadget_erp5_panel.png?format=png',
'gadget_erp5_pt_embedded_form_render.html',
'gadget_erp5_pt_embedded_form_render.js',
'gadget_erp5_pt_form_dialog.html',
'gadget_erp5_pt_form_dialog.js',
'gadget_erp5_pt_form_list.html',
......@@ -107,18 +128,39 @@
'gadget_erp5_sort_editor.html',
'gadget_erp5_sort_editor.js',
'gadget_global.js',
'gadget_html5_element.html',
'gadget_html5_element.js',
'gadget_html5_input.html',
'gadget_html5_input.js',
'gadget_html5_textarea.html',
'gadget_html5_textarea.js',
'gadget_html5_select.html',
'gadget_html5_select.js',
'gadget_erp5_global.js',
'gadget_jio.html',
'gadget_jio.js',
'gadget_translation.html',
'gadget_translation.js',
'gadget_translation_data.js',
'gadget_editor.html',
'gadget_editor.js',
'gadget_button_maximize.html',
'gadget_button_maximize.js',
'handlebars.js',
'i18next.js',
'jiodev.js',
'renderjs.js',
'rsvp.js'
];
'rsvp.js',
'./'
],
required_url_list = [],
i,
len = REQUIRED_FILES.length;
for (i = 0; i < len; i += 1) {
required_url_list.push(
new URL(REQUIRED_FILES[i], location.toString()).toString()
);
}
self.addEventListener('install', function (event) {
// Perform install step: loading each required file into cache
......@@ -136,14 +178,24 @@
});
self.addEventListener('fetch', function (event) {
event.respondWith(
caches.match(event.request)
var url = new URL(event.request.url);
url.hash = '';
if ((event.request.method !== 'GET') ||
(required_url_list.indexOf(url.toString()) === -1)) {
// Try not to use the untrustable fetch function
// It can only be skip synchronously
return;
}
return event.respondWith(
caches.open(CACHE_NAME)
.then(function (cache) {
return cache.match(event.request);
})
.then(function (response) {
// Cache hit - return the response from the cached version
if (response) {
return response;
}
// Not in cache - return the result from the live server
// `fetch` is essentially a "fallback"
return fetch(event.request);
......@@ -168,7 +220,8 @@
.filter(function (key) {
// Filter by keys that don't start with the latest version prefix.
// return !key.startsWith(version);
return key !== CACHE_NAME;
return ((key !== CACHE_NAME) &&
key.startsWith(prefix));
})
.map(function (key) {
/* Return a promise that's fulfilled
......@@ -184,6 +237,4 @@
);
});
}(self, caches, fetch));
}(self, caches, fetch, Promise, URL, location));
\ No newline at end of file
......@@ -228,7 +228,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>952.5891.40125.8465</string> </value>
<value> <string>974.39717.56905.47274</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -246,7 +246,7 @@
</tuple>
<state>
<tuple>
<float>1467035757.8</float>
<float>1553593581.07</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -279,6 +279,16 @@
<value> <string>string</string> </value>
</item>
</dictionary>
<dictionary>
<item>
<key> <string>id</string> </key>
<value> <string>configuration_service_worker_url</string> </value>
</item>
<item>
<key> <string>type</string> </key>
<value> <string>string</string> </value>
</item>
</dictionary>
</tuple>
</value>
</item>
......@@ -353,12 +363,18 @@
</item>
<item>
<key> <string>configuration_manifest_url</string> </key>
<value> <string>gadget_erp5.appcache</string> </value>
<value>
<none/>
</value>
</item>
<item>
<key> <string>configuration_panel_gadget_url</string> </key>
<value> <string>gadget_erp5_panel.html</string> </value>
</item>
<item>
<key> <string>configuration_service_worker_url</string> </key>
<value> <string>gadget_erp5_serviceworker.js</string> </value>
</item>
<item>
<key> <string>configuration_translation_gadget_url</string> </key>
<value> <string>gadget_translation.html</string> </value>
......@@ -600,7 +616,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>965.19244.13768.6758</string> </value>
<value> <string>973.33482.4166.8669</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -618,7 +634,7 @@
</tuple>
<state>
<tuple>
<float>1517843997.55</float>
<float>1553593373.77</float>
<string>UTC</string>
</tuple>
</state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment