mirror of
https://github.com/overleaf/overleaf.git
synced 2024-09-16 02:52:31 -04:00
Merge pull request #225 from sharelatex/ho-hash-on-minifiy-only
only hash the static content when minified is on
This commit is contained in:
commit
0a4febfce6
1 changed files with 19 additions and 16 deletions
|
@ -36,7 +36,6 @@ getFileContent = (filePath)->
|
||||||
logger.log filePath:filePath, "file does not exist for hashing"
|
logger.log filePath:filePath, "file does not exist for hashing"
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
logger.log "Generating file hashes..."
|
|
||||||
pathList = [
|
pathList = [
|
||||||
"#{jsPath}libs/require.js"
|
"#{jsPath}libs/require.js"
|
||||||
"#{jsPath}ide.js"
|
"#{jsPath}ide.js"
|
||||||
|
@ -46,23 +45,27 @@ pathList = [
|
||||||
"/stylesheets/ol-style.css"
|
"/stylesheets/ol-style.css"
|
||||||
]
|
]
|
||||||
|
|
||||||
for path in pathList
|
if !Settings.useMinifiedJs
|
||||||
content = getFileContent(path)
|
logger.log "not using minified JS, not hashing static files"
|
||||||
hash = crypto.createHash("md5").update(content).digest("hex")
|
else
|
||||||
|
logger.log "Generating file hashes..."
|
||||||
splitPath = path.split("/")
|
for path in pathList
|
||||||
filenameSplit = splitPath.pop().split(".")
|
content = getFileContent(path)
|
||||||
filenameSplit.splice(filenameSplit.length-1, 0, hash)
|
hash = crypto.createHash("md5").update(content).digest("hex")
|
||||||
splitPath.push(filenameSplit.join("."))
|
|
||||||
|
splitPath = path.split("/")
|
||||||
|
filenameSplit = splitPath.pop().split(".")
|
||||||
|
filenameSplit.splice(filenameSplit.length-1, 0, hash)
|
||||||
|
splitPath.push(filenameSplit.join("."))
|
||||||
|
|
||||||
hashPath = splitPath.join("/")
|
hashPath = splitPath.join("/")
|
||||||
hashedFiles[path] = hashPath
|
hashedFiles[path] = hashPath
|
||||||
|
|
||||||
fsHashPath = Path.join __dirname, "../../../", "public#{hashPath}"
|
fsHashPath = Path.join __dirname, "../../../", "public#{hashPath}"
|
||||||
fs.writeFileSync(fsHashPath, content)
|
fs.writeFileSync(fsHashPath, content)
|
||||||
|
|
||||||
|
|
||||||
logger.log "Finished hashing static content"
|
logger.log "Finished hashing static content"
|
||||||
|
|
||||||
cdnAvailable = Settings.cdn?.web?.host?
|
cdnAvailable = Settings.cdn?.web?.host?
|
||||||
darkCdnAvailable = Settings.cdn?.web?.darkHost?
|
darkCdnAvailable = Settings.cdn?.web?.darkHost?
|
||||||
|
@ -121,7 +124,7 @@ module.exports = (app, webRouter, privateApiRouter, publicApiRouter)->
|
||||||
res.locals.buildJsPath = (jsFile, opts = {})->
|
res.locals.buildJsPath = (jsFile, opts = {})->
|
||||||
path = Path.join(jsPath, jsFile)
|
path = Path.join(jsPath, jsFile)
|
||||||
|
|
||||||
if opts.hashedPath
|
if opts.hashedPath && hashedFiles[path]?
|
||||||
path = hashedFiles[path]
|
path = hashedFiles[path]
|
||||||
|
|
||||||
if !opts.qs?
|
if !opts.qs?
|
||||||
|
@ -141,7 +144,7 @@ module.exports = (app, webRouter, privateApiRouter, publicApiRouter)->
|
||||||
|
|
||||||
res.locals.buildCssPath = (cssFile, opts)->
|
res.locals.buildCssPath = (cssFile, opts)->
|
||||||
path = Path.join("/stylesheets/", cssFile)
|
path = Path.join("/stylesheets/", cssFile)
|
||||||
if opts?.hashedPath
|
if opts?.hashedPath && hashedFiles[path]?
|
||||||
hashedPath = hashedFiles[path]
|
hashedPath = hashedFiles[path]
|
||||||
return Url.resolve(staticFilesBase, hashedPath)
|
return Url.resolve(staticFilesBase, hashedPath)
|
||||||
return Url.resolve(staticFilesBase, path)
|
return Url.resolve(staticFilesBase, path)
|
||||||
|
|
Loading…
Reference in a new issue