Javascript compression now caches

This commit is contained in:
bingus_violet 2024-06-25 18:41:15 -05:00
parent 0364cca624
commit 67d8e3bec2

View file

@ -24,6 +24,8 @@ var lastPregen = 0
var pregenFiles = [] var pregenFiles = []
var javascriptCache = {}
var globResult = glob.globSync("**/static/**/*.html", { absolute: true }) var globResult = glob.globSync("**/static/**/*.html", { absolute: true })
for (var i = 0; i < globResult.length; i++) { for (var i = 0; i < globResult.length; i++) {
var result = globResult[i] var result = globResult[i]
@ -328,11 +330,14 @@ module.exports = {
if (!filePath.includes(".js")) { if (!filePath.includes(".js")) {
data = htmlMinifier.minify(data) data = htmlMinifier.minify(data)
} else { } else {
data = await minify({ if (!javascriptCache[filePath]) {
javascriptCache[filePath] = await minify({
compressor: uglifyJs, compressor: uglifyJs,
content: data content: data
}) })
} }
data = javascriptCache[filePath]
}
res.send(data) res.send(data)
} else { } else {