From 70298ba65c6bce0a2325c426c9035c1de9158495 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Tue, 19 Dec 2017 13:13:31 +0000 Subject: [PATCH] only hash the static content when minified is on --- .../infrastructure/ExpressLocals.coffee | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/services/web/app/coffee/infrastructure/ExpressLocals.coffee b/services/web/app/coffee/infrastructure/ExpressLocals.coffee index 002a10ca89..a820a8500b 100644 --- a/services/web/app/coffee/infrastructure/ExpressLocals.coffee +++ b/services/web/app/coffee/infrastructure/ExpressLocals.coffee @@ -36,7 +36,6 @@ getFileContent = (filePath)-> logger.log filePath:filePath, "file does not exist for hashing" return "" -logger.log "Generating file hashes..." pathList = [ "#{jsPath}libs/require.js" "#{jsPath}ide.js" @@ -46,23 +45,27 @@ pathList = [ "/stylesheets/ol-style.css" ] -for path in pathList - content = getFileContent(path) - hash = crypto.createHash("md5").update(content).digest("hex") - - splitPath = path.split("/") - filenameSplit = splitPath.pop().split(".") - filenameSplit.splice(filenameSplit.length-1, 0, hash) - splitPath.push(filenameSplit.join(".")) +if !Settings.useMinifiedJs + logger.log "not using minified JS, not hashing static files" +else + logger.log "Generating file hashes..." + for path in pathList + content = getFileContent(path) + hash = crypto.createHash("md5").update(content).digest("hex") + + splitPath = path.split("/") + filenameSplit = splitPath.pop().split(".") + filenameSplit.splice(filenameSplit.length-1, 0, hash) + splitPath.push(filenameSplit.join(".")) - hashPath = splitPath.join("/") - hashedFiles[path] = hashPath + hashPath = splitPath.join("/") + hashedFiles[path] = hashPath - fsHashPath = Path.join __dirname, "../../../", "public#{hashPath}" - fs.writeFileSync(fsHashPath, content) + fsHashPath = Path.join __dirname, "../../../", "public#{hashPath}" + fs.writeFileSync(fsHashPath, content) -logger.log "Finished hashing static content" + logger.log "Finished hashing static content" cdnAvailable = Settings.cdn?.web?.host? darkCdnAvailable = Settings.cdn?.web?.darkHost? @@ -121,7 +124,7 @@ module.exports = (app, webRouter, privateApiRouter, publicApiRouter)-> res.locals.buildJsPath = (jsFile, opts = {})-> path = Path.join(jsPath, jsFile) - if opts.hashedPath + if opts.hashedPath && hashedFiles[path]? path = hashedFiles[path] if !opts.qs? @@ -141,7 +144,7 @@ module.exports = (app, webRouter, privateApiRouter, publicApiRouter)-> res.locals.buildCssPath = (cssFile, opts)-> path = Path.join("/stylesheets/", cssFile) - if opts?.hashedPath + if opts?.hashedPath && hashedFiles[path]? hashedPath = hashedFiles[path] return Url.resolve(staticFilesBase, hashedPath) return Url.resolve(staticFilesBase, path)