automatically minify js files
improve loading times
This commit is contained in:
parent
35d91586f6
commit
f53e9ee510
17
package-lock.json
generated
17
package-lock.json
generated
@ -20,6 +20,7 @@
|
||||
"jimp": "^0.16.1",
|
||||
"lru-cache": "^7.14.0",
|
||||
"mysql": "^2.18.1",
|
||||
"uglify-js": "^3.17.0",
|
||||
"unsafe_encrypt": "^1.0.4",
|
||||
"ws": "^8.8.1"
|
||||
}
|
||||
@ -1755,6 +1756,17 @@
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/uglify-js": {
|
||||
"version": "3.17.0",
|
||||
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.17.0.tgz",
|
||||
"integrity": "sha512-aTeNPVmgIMPpm1cxXr2Q/nEbvkmV8yq66F3om7X3P/cvOXQ0TMQ64Wk63iyT1gPlmdmGzjGpyLh1f3y8MZWXGg==",
|
||||
"bin": {
|
||||
"uglifyjs": "bin/uglifyjs"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/uid-safe": {
|
||||
"version": "2.1.5",
|
||||
"resolved": "https://registry.npmjs.org/uid-safe/-/uid-safe-2.1.5.tgz",
|
||||
@ -3199,6 +3211,11 @@
|
||||
"mime-types": "~2.1.24"
|
||||
}
|
||||
},
|
||||
"uglify-js": {
|
||||
"version": "3.17.0",
|
||||
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.17.0.tgz",
|
||||
"integrity": "sha512-aTeNPVmgIMPpm1cxXr2Q/nEbvkmV8yq66F3om7X3P/cvOXQ0TMQ64Wk63iyT1gPlmdmGzjGpyLh1f3y8MZWXGg=="
|
||||
},
|
||||
"uid-safe": {
|
||||
"version": "2.1.5",
|
||||
"resolved": "https://registry.npmjs.org/uid-safe/-/uid-safe-2.1.5.tgz",
|
||||
|
@ -11,6 +11,7 @@
|
||||
"jimp": "^0.16.1",
|
||||
"lru-cache": "^7.14.0",
|
||||
"mysql": "^2.18.1",
|
||||
"uglify-js": "^3.17.0",
|
||||
"unsafe_encrypt": "^1.0.4",
|
||||
"ws": "^8.8.1"
|
||||
},
|
||||
|
22
server.js
22
server.js
@ -834,13 +834,23 @@ import LRU from "lru-cache"
|
||||
|
||||
ejs.cache = new LRU({max:20})
|
||||
|
||||
function load_var(fina) {
|
||||
let out = readFileSync(fina)
|
||||
if(fina.endsWith(".js")) {
|
||||
return min_js(out.toString()).code
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
import {minify as min_js} from "uglify-js"
|
||||
|
||||
const global_page_variables = {
|
||||
globalcss: readFileSync("./css/global.css"),
|
||||
httppostjs: readFileSync("./js/httppost.js"),
|
||||
addnavbar: readFileSync("./js/addnavbar.js"),
|
||||
markdownjs: readFileSync("./js/markdown.js"),
|
||||
htmlescapejs: readFileSync("./js/htmlescape.js"),
|
||||
warnmessagejs: readFileSync("./js/warn_message.js")
|
||||
globalcss: load_var("./css/global.css"),
|
||||
httppostjs: load_var("./js/httppost.js"),
|
||||
addnavbar: load_var("./js/addnavbar.js"),
|
||||
markdownjs: load_var("./js/markdown.js"),
|
||||
htmlescapejs: load_var("./js/htmlescape.js"),
|
||||
warnmessagejs: load_var("./js/warn_message.js")
|
||||
}
|
||||
|
||||
router.get("/*", async function(request, response) {
|
||||
|
@ -6,7 +6,7 @@
|
||||
<style>
|
||||
<%- globalcss %>
|
||||
</style>
|
||||
<link rel="stylesheet" href="/css/posts.css">
|
||||
<link href="/css/posts.css" rel="preload" as="style" onload="this.rel='stylesheet'">
|
||||
<script type="text/javascript"><%- httppostjs %></script>
|
||||
<script type="text/javascript"><%- htmlescapejs %></script>
|
||||
<script type="text/javascript"><%- addnavbar %></script>
|
||||
@ -39,6 +39,6 @@
|
||||
</div>
|
||||
<div class="posts" id="posts"></div>
|
||||
</div>
|
||||
<script type="text/javascript" src="/js/posts.js"></script>
|
||||
<script type="text/javascript" src="/js/posts.js" async></script>
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
x
Reference in New Issue
Block a user