From 80e6a660be2f3fb938b938541206c94ba160b994 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Tue, 12 Dec 2017 17:21:01 +0000 Subject: [PATCH] wip, this does not work minified yet for some reason lib.js is not being requested no, console errors or network errors --- services/web/.gitignore | 9 ++++++++ .../infrastructure/ExpressLocals.coffee | 22 ++++++++++++++++++- services/web/app/views/layout.pug | 4 ++-- services/web/app/views/project/editor.pug | 4 ++-- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/services/web/.gitignore b/services/web/.gitignore index a48481690a..8df4ab2fa6 100644 --- a/services/web/.gitignore +++ b/services/web/.gitignore @@ -67,6 +67,15 @@ public/minjs/ Gemfile.lock +public/js/libs/fineuploader-5.15.4.*.js +public/js/libs/fineuploader-*.js +public/js/libs/pdfjs-1.7.225/compatibility.*.js +public/js/libs/pdfjs-1.7.225/pdf.*.js +public/js/libs/pdfjs-1.7.225/pdf.worker.*.js +public/js/libs/require.*.js +public/stylesheets/ol-style.*.css +public/stylesheets/style.*.css + *.swp .DS_Store diff --git a/services/web/app/coffee/infrastructure/ExpressLocals.coffee b/services/web/app/coffee/infrastructure/ExpressLocals.coffee index b126819f56..d2aeae655c 100644 --- a/services/web/app/coffee/infrastructure/ExpressLocals.coffee +++ b/services/web/app/coffee/infrastructure/ExpressLocals.coffee @@ -13,6 +13,7 @@ Url = require "url" PackageVersions = require "./PackageVersions" htmlEncoder = new require("node-html-encoder").Encoder("numerical") fingerprints = {} +hashedFiles = {} Path = require 'path' Features = require "./Features" @@ -59,6 +60,19 @@ for paths in pathList logger.log "#{filePath}: #{hash}" fingerprints[filePath] = hash + if paths.length == 1 + #todo deal with ace multi file hash + path = paths[0] + splitPath = path.split("/") + filenameSplit = splitPath.pop().split(".") + filenameSplit.splice(filenameSplit.length-1, 0, hash) + splitPath.push(filenameSplit.join(".")) + hashPath = splitPath.join("/") + fsHashPath = Path.join __dirname, "../../../", "public#{hashPath}" + fs.writeFileSync(fsHashPath, content) + hashedFiles[paths] = hashPath + + getFingerprint = (path) -> if fingerprints[path]? return fingerprints[path] @@ -123,6 +137,9 @@ module.exports = (app, webRouter, privateApiRouter, publicApiRouter)-> res.locals.buildJsPath = (jsFile, opts = {})-> path = Path.join(jsPath, jsFile) + if opts.hashedPath + return hashedFiles[path] + doFingerPrint = opts.fingerprint != false if !opts.qs? @@ -140,8 +157,11 @@ module.exports = (app, webRouter, privateApiRouter, publicApiRouter)-> path = path + "?" + qs return path - res.locals.buildCssPath = (cssFile)-> + res.locals.buildCssPath = (cssFile, opts)-> path = Path.join("/stylesheets/", cssFile) + if opts.hashedPath + hashedPath = hashedFiles[path] + return Url.resolve(staticFilesBase, hashedPath) return Url.resolve(staticFilesBase, path) + "?fingerprint=" + getFingerprint(path) res.locals.buildImgPath = (imgFile)-> diff --git a/services/web/app/views/layout.pug b/services/web/app/views/layout.pug index e12d7d6f81..537417dce3 100644 --- a/services/web/app/views/layout.pug +++ b/services/web/app/views/layout.pug @@ -23,7 +23,7 @@ html(itemscope, itemtype='http://schema.org/Product') link(rel="apple-touch-icon-precomposed", href="/" + settings.brandPrefix + "apple-touch-icon-precomposed.png") link(rel="mask-icon", href="/" + settings.brandPrefix + "mask-favicon.svg", color="#a93529") - link(rel='stylesheet', href=buildCssPath("/" + settings.brandPrefix + "style.css")) + link(rel='stylesheet', href=buildCssPath("/" + settings.brandPrefix + "style.css", {hashedPath:true})) block _headLinks @@ -152,7 +152,7 @@ html(itemscope, itemtype='http://schema.org/Product') } }; script( - data-main=buildJsPath('main.js', {fingerprint:false}), + data-main=buildJsPath('main.js', {hashedPath:true}), baseurl=fullJsPath, src=buildJsPath('libs/require.js') ) diff --git a/services/web/app/views/project/editor.pug b/services/web/app/views/project/editor.pug index ec1d129714..c49afee0b2 100644 --- a/services/web/app/views/project/editor.pug +++ b/services/web/app/views/project/editor.pug @@ -161,8 +161,8 @@ block requirejs window.uiConfig = JSON.parse('!{JSON.stringify(uiConfig).replace(/\//g, "\\/")}'); script( - data-main=buildJsPath("ide.js", {fingerprint:false}), + data-main=buildJsPath("ide.js", {hashedPath:true}), baseurl=fullJsPath, data-ace-base=buildJsPath(lib('ace'), {fingerprint:false}), - src=buildJsPath('libs/require.js') + src=buildJsPath('libs/require.js', {hashedPath:true}) )