Asynchronous js loading

This commit is contained in:
NielsAD
2018-09-16 12:30:45 +02:00
parent 4f3d14d0f3
commit 42f427361d
3 changed files with 57 additions and 4 deletions

View File

@@ -32,3 +32,53 @@ Usage
#### Example
`./autoindex -a=":4000" -i=5m -d=/tmp/autoindex.db -cached -r=/mnt/storage`
Behind nginx
------------
Example configuration for running `autoindex` behind an `nginx` proxy.
```
upstream autoindex {
server 127.0.0.1:4000;
keepalive 8;
}
map $request_uri $request_basename {
~/(?<captured_request_basename>[^/?]*)(?:\?|$) $captured_request_basename;
}
map $request_uri $idx_path {
~/(?<captured_request_path>[^?]*)(?<captured_request_args>\?.*)?$ $captured_request_path/$cap$
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name _;
root /opt/autoindex/public;
location / {
rewrite ^/(.*)/$ /$1 permanent;
try_files $uri /index.html;
expires 1y;
}
location = /index.html {
http2_push /idx/$idx_path;
expires 1d;
}
location ^~ /dl/ {
limit_rate 1m;
add_header Content-Disposition 'attachment; filename="$request_basename"';
add_header X-Robots-Tag "noindex, nofollow, nosnippet, noarchive";
}
location ~ ^(/idx/|/urllist.txt) {
proxy_pass https://autoindex;
}
}
```

View File

@@ -9,7 +9,7 @@
<title>Archive - toom.io</title>
<link rel="shortcut icon" href="/favicon.ico?201809121" />
<link rel="stylesheet" type="text/css" href="/style.css?201809141">
<script src="/script.js?201809141"></script>
<script src="/script.js?201809161" async></script>
</head>
<body class=loading>
<header>

View File

@@ -85,8 +85,7 @@ function setPath(crumbs, files, q, path, query) {
req.open("GET", "/idx/" + path + query, true);
req.send();
}
document.addEventListener("DOMContentLoaded", function() {
function onLoad() {
const path = document.getElementById("path");
const files = document.getElementById("files");
const search = document.getElementById("search");
@@ -102,4 +101,8 @@ document.addEventListener("DOMContentLoaded", function() {
const s = q.value ? "?r=1&q=" + encodeURIComponent(q.value) : "";
setPath(path, files, q, document.location.pathname, s);
});
});
}
if (document.readyState === "loading")
document.addEventListener("DOMContentLoaded", onLoad);
else
onLoad();