up2k.js: defer worker startup until needed

This commit is contained in:
ed 2022-09-05 00:55:52 +02:00
parent 995cd10df8
commit 635ab25013
3 changed files with 16 additions and 9 deletions

View file

@ -408,7 +408,7 @@ class HttpCli(object):
self.out_headers.update(NO_CACHE)
return
n = "604800" if cache == "i" else cache or "69"
n = "604869" if cache == "i" else cache or "69"
self.out_headers["Cache-Control"] = "max-age=" + n
def k304(self) -> bool:
@ -1714,7 +1714,7 @@ class HttpCli(object):
# send reply
if is_compressed:
self.out_headers["Cache-Control"] = "max-age=573"
self.out_headers["Cache-Control"] = "max-age=604869"
else:
self.permit_caching()

View file

@ -719,12 +719,10 @@ function up2k_init(subtle) {
"gotallfiles": [gotallfiles] // hooks
};
if (window.WebAssembly) {
for (var a = 0; a < Math.min(navigator.hardwareConcurrency || 4, 16); a++)
hws.push(new Worker('/.cpr/w.hash.js'));
console.log(hws.length + " hashers ready");
}
setTimeout(function () {
if (window.WebAssembly && !hws.length)
fetch('/.cpr/w.hash.js' + CB);
}, 1000);
function showmodal(msg) {
ebi('u2notbtn').innerHTML = msg;
@ -1188,6 +1186,13 @@ function up2k_init(subtle) {
var evpath = get_evpath(),
draw_each = good_files.length < 50;
if (window.WebAssembly && !hws.length) {
for (var a = 0; a < Math.min(navigator.hardwareConcurrency || 4, 16); a++)
hws.push(new Worker('/.cpr/w.hash.js' + CB));
console.log(hws.length + " hashers");
}
if (!uc.az)
good_files.sort(function (a, b) {
a = a[0].size;

View file

@ -7,6 +7,7 @@ if (!window['console'])
var wah = '',
CB = '?_=' + Date.now(),
HALFMAX = 8192 * 8192 * 8192 * 8192,
HTTPS = (window.location + '').indexOf('https:') === 0,
TOUCH = 'ontouchstart' in window,
@ -15,8 +16,9 @@ var wah = '',
IPHONE = TOUCH && /iPhone|iPad|iPod/i.test(navigator.userAgent),
WINDOWS = navigator.platform ? navigator.platform == 'Win32' : /Windows/.test(navigator.userAgent);
try {
CB = '?' + document.currentScript.src.split('?').pop();
if (navigator.userAgentData.mobile)
MOBILE = true;