From 80e6a660be2f3fb938b938541206c94ba160b994 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Tue, 12 Dec 2017 17:21:01 +0000 Subject: [PATCH 01/13] 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}) ) From 65efbbce537bfe4a5428b85848c06a71c8ee1ca0 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Wed, 13 Dec 2017 13:06:38 +0000 Subject: [PATCH 02/13] seems to work now. --- .../web/app/coffee/infrastructure/ExpressLocals.coffee | 8 ++++++-- services/web/app/views/layout.pug | 6 +++--- services/web/app/views/project/editor.pug | 6 ++++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/services/web/app/coffee/infrastructure/ExpressLocals.coffee b/services/web/app/coffee/infrastructure/ExpressLocals.coffee index d2aeae655c..7aef6e5424 100644 --- a/services/web/app/coffee/infrastructure/ExpressLocals.coffee +++ b/services/web/app/coffee/infrastructure/ExpressLocals.coffee @@ -134,11 +134,15 @@ module.exports = (app, webRouter, privateApiRouter, publicApiRouter)-> res.locals.fullJsPath = Url.resolve(staticFilesBase, jsPath) res.locals.lib = PackageVersions.lib + + res.locals.buildJsPath = (jsFile, opts = {})-> path = Path.join(jsPath, jsFile) + + # TODO CDN? if opts.hashedPath - return hashedFiles[path] + path = hashedFiles[path] doFingerPrint = opts.fingerprint != false @@ -159,7 +163,7 @@ module.exports = (app, webRouter, privateApiRouter, publicApiRouter)-> res.locals.buildCssPath = (cssFile, opts)-> path = Path.join("/stylesheets/", cssFile) - if opts.hashedPath + if opts?.hashedPath hashedPath = hashedFiles[path] return Url.resolve(staticFilesBase, hashedPath) return Url.resolve(staticFilesBase, path) + "?fingerprint=" + getFingerprint(path) diff --git a/services/web/app/views/layout.pug b/services/web/app/views/layout.pug index 537417dce3..d9bba35f0b 100644 --- a/services/web/app/views/layout.pug +++ b/services/web/app/views/layout.pug @@ -142,9 +142,9 @@ html(itemscope, itemtype='http://schema.org/Product') window.requirejs = { "paths" : { "moment": "libs/#{lib('moment')}", - "fineuploader": "libs/#{lib('fineuploader')}" + "fineuploader": "libs/#{lib('fineuploader')}", + "main": "#{buildJsPath('main.js', {hashedPath:true, fingerprint:false}).slice(0,-3)}", }, - "urlArgs": "fingerprint=#{fingerprint(jsPath + 'main.js')}-#{fingerprint(jsPath + 'libs.js')}", "config":{ "moment":{ "noGlobal": true @@ -152,7 +152,7 @@ html(itemscope, itemtype='http://schema.org/Product') } }; script( - data-main=buildJsPath('main.js', {hashedPath:true}), + data-main=buildJsPath('main.js', {hashedPath:false, fingerprint:false}), 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 c49afee0b2..a37ac6e6d5 100644 --- a/services/web/app/views/project/editor.pug +++ b/services/web/app/views/project/editor.pug @@ -131,7 +131,9 @@ block requirejs "pdfjs-dist/build/pdf": "libs/#{lib('pdfjs')}/pdf", "pdfjs-dist/build/pdf.worker": "#{pdfWorkerPath}", "ace": "#{lib('ace')}", - "fineuploader": "libs/#{lib('fineuploader')}" + "fineuploader": "libs/#{lib('fineuploader')}", + "ide": "#{buildJsPath('ide.js', {hashedPath:true, fingerprint:false}).slice(0,-3)}", + }, "urlArgs" : "fingerprint=#{fingerprint(jsPath + 'ide.js')}-#{fingerprint(jsPath + 'libs.js')}", "waitSeconds": 0, @@ -161,7 +163,7 @@ block requirejs window.uiConfig = JSON.parse('!{JSON.stringify(uiConfig).replace(/\//g, "\\/")}'); script( - data-main=buildJsPath("ide.js", {hashedPath:true}), + data-main=buildJsPath("ide.js", {hashedPath:false}), baseurl=fullJsPath, data-ace-base=buildJsPath(lib('ace'), {fingerprint:false}), src=buildJsPath('libs/require.js', {hashedPath:true}) From 88334959d708c2cef12b7fc5556d9a39823b8300 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Wed, 13 Dec 2017 14:13:45 +0000 Subject: [PATCH 03/13] added remove extension --- services/web/app/coffee/infrastructure/ExpressLocals.coffee | 3 +++ services/web/app/views/layout.pug | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/services/web/app/coffee/infrastructure/ExpressLocals.coffee b/services/web/app/coffee/infrastructure/ExpressLocals.coffee index 7aef6e5424..33dbe2f34a 100644 --- a/services/web/app/coffee/infrastructure/ExpressLocals.coffee +++ b/services/web/app/coffee/infrastructure/ExpressLocals.coffee @@ -157,6 +157,9 @@ module.exports = (app, webRouter, privateApiRouter, publicApiRouter)-> qs = querystring.stringify(opts.qs) + if opts.removeExtension == true + path = path.slice(0,-3) + if qs? and qs.length > 0 path = path + "?" + qs return path diff --git a/services/web/app/views/layout.pug b/services/web/app/views/layout.pug index d9bba35f0b..0220a5af71 100644 --- a/services/web/app/views/layout.pug +++ b/services/web/app/views/layout.pug @@ -143,7 +143,7 @@ html(itemscope, itemtype='http://schema.org/Product') "paths" : { "moment": "libs/#{lib('moment')}", "fineuploader": "libs/#{lib('fineuploader')}", - "main": "#{buildJsPath('main.js', {hashedPath:true, fingerprint:false}).slice(0,-3)}", + "main": "#{buildJsPath('main.js', {hashedPath:true, fingerprint:false, removeExtension:true})}" }, "config":{ "moment":{ From 357617d952f15dfb679470fa6e6d19a416899601 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Wed, 13 Dec 2017 14:19:19 +0000 Subject: [PATCH 04/13] works with libs compiled into it --- services/web/Gruntfile.coffee | 5 ++--- services/web/app/views/project/editor.pug | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/services/web/Gruntfile.coffee b/services/web/Gruntfile.coffee index c49add4a91..374177e7d2 100644 --- a/services/web/Gruntfile.coffee +++ b/services/web/Gruntfile.coffee @@ -205,11 +205,10 @@ module.exports = (grunt) -> modules: [ { name: "main", - exclude: ["libs"] }, { name: "ide", - exclude: ["libs", "pdfjs-dist/build/pdf"] - }, { + exclude: ["pdfjs-dist/build/pdf"] + },{ name: "libs" },{ name: "ace/mode-latex" diff --git a/services/web/app/views/project/editor.pug b/services/web/app/views/project/editor.pug index a37ac6e6d5..19b2478f48 100644 --- a/services/web/app/views/project/editor.pug +++ b/services/web/app/views/project/editor.pug @@ -132,7 +132,7 @@ block requirejs "pdfjs-dist/build/pdf.worker": "#{pdfWorkerPath}", "ace": "#{lib('ace')}", "fineuploader": "libs/#{lib('fineuploader')}", - "ide": "#{buildJsPath('ide.js', {hashedPath:true, fingerprint:false}).slice(0,-3)}", + "ide": "#{buildJsPath('ide.js', {hashedPath:true, fingerprint:false, removeExtension:true})}" }, "urlArgs" : "fingerprint=#{fingerprint(jsPath + 'ide.js')}-#{fingerprint(jsPath + 'libs.js')}", @@ -163,7 +163,7 @@ block requirejs window.uiConfig = JSON.parse('!{JSON.stringify(uiConfig).replace(/\//g, "\\/")}'); script( - data-main=buildJsPath("ide.js", {hashedPath:false}), + data-main=buildJsPath("ide.js", {hashedPath:false, fingerprint:false}), baseurl=fullJsPath, data-ace-base=buildJsPath(lib('ace'), {fingerprint:false}), src=buildJsPath('libs/require.js', {hashedPath:true}) From ccbb15c82ef038bc8a3a23eeb7c6402fa47dd8e0 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Wed, 13 Dec 2017 14:54:08 +0000 Subject: [PATCH 05/13] remove fingerprint from ide --- services/web/app/views/project/editor.pug | 2 -- 1 file changed, 2 deletions(-) diff --git a/services/web/app/views/project/editor.pug b/services/web/app/views/project/editor.pug index 19b2478f48..38ffdd3402 100644 --- a/services/web/app/views/project/editor.pug +++ b/services/web/app/views/project/editor.pug @@ -133,9 +133,7 @@ block requirejs "ace": "#{lib('ace')}", "fineuploader": "libs/#{lib('fineuploader')}", "ide": "#{buildJsPath('ide.js', {hashedPath:true, fingerprint:false, removeExtension:true})}" - }, - "urlArgs" : "fingerprint=#{fingerprint(jsPath + 'ide.js')}-#{fingerprint(jsPath + 'libs.js')}", "waitSeconds": 0, "shim": { "pdfjs-dist/build/pdf": { From f021f21f11c3c5049a555fc84edb70f71a3733ad Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Wed, 13 Dec 2017 16:37:51 +0000 Subject: [PATCH 06/13] only hash when minified --- services/web/app/views/layout.pug | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/web/app/views/layout.pug b/services/web/app/views/layout.pug index 0220a5af71..f32e90a6ed 100644 --- a/services/web/app/views/layout.pug +++ b/services/web/app/views/layout.pug @@ -143,7 +143,7 @@ html(itemscope, itemtype='http://schema.org/Product') "paths" : { "moment": "libs/#{lib('moment')}", "fineuploader": "libs/#{lib('fineuploader')}", - "main": "#{buildJsPath('main.js', {hashedPath:true, fingerprint:false, removeExtension:true})}" + "main": "#{buildJsPath('main.js', {hashedPath:settings.useMinifiedJs, fingerprint:false, removeExtension:true})}", }, "config":{ "moment":{ From 716b3092088ee98e5891b36d437d7a468c7eddf2 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Wed, 13 Dec 2017 16:50:18 +0000 Subject: [PATCH 07/13] remove todo statments --- services/web/app/coffee/infrastructure/ExpressLocals.coffee | 3 --- 1 file changed, 3 deletions(-) diff --git a/services/web/app/coffee/infrastructure/ExpressLocals.coffee b/services/web/app/coffee/infrastructure/ExpressLocals.coffee index 33dbe2f34a..7cac6743e5 100644 --- a/services/web/app/coffee/infrastructure/ExpressLocals.coffee +++ b/services/web/app/coffee/infrastructure/ExpressLocals.coffee @@ -61,7 +61,6 @@ for paths in pathList fingerprints[filePath] = hash if paths.length == 1 - #todo deal with ace multi file hash path = paths[0] splitPath = path.split("/") filenameSplit = splitPath.pop().split(".") @@ -139,8 +138,6 @@ module.exports = (app, webRouter, privateApiRouter, publicApiRouter)-> res.locals.buildJsPath = (jsFile, opts = {})-> path = Path.join(jsPath, jsFile) - - # TODO CDN? if opts.hashedPath path = hashedFiles[path] From 490c56c692cae2e856f86fca659bbf724f6a1cc2 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Wed, 13 Dec 2017 17:07:58 +0000 Subject: [PATCH 08/13] libs -> libraries don't use hash in non minjs version --- services/web/Gruntfile.coffee | 5 +++-- services/web/app/coffee/infrastructure/ExpressLocals.coffee | 2 +- services/web/app/views/layout.pug | 1 + services/web/app/views/project/editor.pug | 3 ++- services/web/public/coffee/base.coffee | 2 +- services/web/public/coffee/{libs.coffee => libraries.coffee} | 0 services/web/public/coffee/utils/underscore.coffee | 2 +- 7 files changed, 9 insertions(+), 6 deletions(-) rename services/web/public/coffee/{libs.coffee => libraries.coffee} (100%) diff --git a/services/web/Gruntfile.coffee b/services/web/Gruntfile.coffee index 374177e7d2..a0000360b3 100644 --- a/services/web/Gruntfile.coffee +++ b/services/web/Gruntfile.coffee @@ -205,11 +205,12 @@ module.exports = (grunt) -> modules: [ { name: "main", + exclude: ["libraries"] }, { name: "ide", - exclude: ["pdfjs-dist/build/pdf"] + exclude: ["pdfjs-dist/build/pdf", "libraries"] },{ - name: "libs" + name: "libraries" },{ name: "ace/mode-latex" },{ diff --git a/services/web/app/coffee/infrastructure/ExpressLocals.coffee b/services/web/app/coffee/infrastructure/ExpressLocals.coffee index 7cac6743e5..46f9eefb86 100644 --- a/services/web/app/coffee/infrastructure/ExpressLocals.coffee +++ b/services/web/app/coffee/infrastructure/ExpressLocals.coffee @@ -43,7 +43,7 @@ pathList = [ ["#{jsPath}libs/require.js"] ["#{jsPath}ide.js"] ["#{jsPath}main.js"] - ["#{jsPath}libs.js"] + ["#{jsPath}libraries.js"] ["#{jsPath}#{ace}/ace.js","#{jsPath}#{ace}/mode-latex.js","#{jsPath}#{ace}/worker-latex.js","#{jsPath}#{ace}/snippets/latex.js"] ["#{jsPath}libs/#{pdfjs}/pdf.js"] ["#{jsPath}libs/#{pdfjs}/pdf.worker.js"] diff --git a/services/web/app/views/layout.pug b/services/web/app/views/layout.pug index f32e90a6ed..5aa41c56c7 100644 --- a/services/web/app/views/layout.pug +++ b/services/web/app/views/layout.pug @@ -144,6 +144,7 @@ html(itemscope, itemtype='http://schema.org/Product') "moment": "libs/#{lib('moment')}", "fineuploader": "libs/#{lib('fineuploader')}", "main": "#{buildJsPath('main.js', {hashedPath:settings.useMinifiedJs, fingerprint:false, removeExtension:true})}", + "libraries": "#{buildJsPath('libraries.js', {hashedPath:settings.useMinifiedJs, fingerprint:false, removeExtension:true})}", }, "config":{ "moment":{ diff --git a/services/web/app/views/project/editor.pug b/services/web/app/views/project/editor.pug index 38ffdd3402..c3fd408e10 100644 --- a/services/web/app/views/project/editor.pug +++ b/services/web/app/views/project/editor.pug @@ -132,7 +132,8 @@ block requirejs "pdfjs-dist/build/pdf.worker": "#{pdfWorkerPath}", "ace": "#{lib('ace')}", "fineuploader": "libs/#{lib('fineuploader')}", - "ide": "#{buildJsPath('ide.js', {hashedPath:true, fingerprint:false, removeExtension:true})}" + "ide": "#{buildJsPath('ide.js', {hashedPath:settings.useMinifiedJs, fingerprint:false, removeExtension:true})}", + "libraries": "#{buildJsPath('libraries.js', {hashedPath:settings.useMinifiedJs, fingerprint:false, removeExtension:true})}", }, "waitSeconds": 0, "shim": { diff --git a/services/web/public/coffee/base.coffee b/services/web/public/coffee/base.coffee index 03d0ada365..c3847c9342 100644 --- a/services/web/public/coffee/base.coffee +++ b/services/web/public/coffee/base.coffee @@ -1,5 +1,5 @@ define [ - "libs" + "libraries" "modules/recursionHelper" "modules/errorCatcher" "modules/localStorage" diff --git a/services/web/public/coffee/libs.coffee b/services/web/public/coffee/libraries.coffee similarity index 100% rename from services/web/public/coffee/libs.coffee rename to services/web/public/coffee/libraries.coffee diff --git a/services/web/public/coffee/utils/underscore.coffee b/services/web/public/coffee/utils/underscore.coffee index 7a1551f90b..944abccb5d 100644 --- a/services/web/public/coffee/utils/underscore.coffee +++ b/services/web/public/coffee/utils/underscore.coffee @@ -1,5 +1,5 @@ define [ - "libs" + "libraries" ], () -> angular.module('underscore', []).factory '_', -> return window._ From bbbba701b019682b026634ab20ff6b3a827c99b7 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Thu, 14 Dec 2017 10:21:53 +0000 Subject: [PATCH 09/13] Update editor.pug --- services/web/app/views/project/editor.pug | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/web/app/views/project/editor.pug b/services/web/app/views/project/editor.pug index c3fd408e10..582e0f3541 100644 --- a/services/web/app/views/project/editor.pug +++ b/services/web/app/views/project/editor.pug @@ -165,5 +165,5 @@ block requirejs data-main=buildJsPath("ide.js", {hashedPath:false, fingerprint:false}), baseurl=fullJsPath, data-ace-base=buildJsPath(lib('ace'), {fingerprint:false}), - src=buildJsPath('libs/require.js', {hashedPath:true}) + src=buildJsPath('libs/require.js', {hashedPath:false}) ) From 288af6772afcc2dcf3398ec927e5263965fdff50 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Thu, 14 Dec 2017 10:59:46 +0000 Subject: [PATCH 10/13] write hashes for all files we fingerprint --- services/web/.gitignore | 10 +++++++--- .../web/app/coffee/infrastructure/ExpressLocals.coffee | 3 +-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/services/web/.gitignore b/services/web/.gitignore index 8df4ab2fa6..d0053e47c8 100644 --- a/services/web/.gitignore +++ b/services/web/.gitignore @@ -69,12 +69,16 @@ 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/pdfjs-*/compatibility.*.js +public/js/libs/pdfjs-*/pdf.*.js +public/js/libs/pdfjs-*/pdf.worker.*.js public/js/libs/require.*.js public/stylesheets/ol-style.*.css public/stylesheets/style.*.css +public/js/ace-*/ace.*.js +public/js/ace-*/mode-latex.*.js +public/js/ace-*/snippets/latex.*.js +public/js/ace-*/worker-latex.*.js *.swp .DS_Store diff --git a/services/web/app/coffee/infrastructure/ExpressLocals.coffee b/services/web/app/coffee/infrastructure/ExpressLocals.coffee index 46f9eefb86..51b44a8996 100644 --- a/services/web/app/coffee/infrastructure/ExpressLocals.coffee +++ b/services/web/app/coffee/infrastructure/ExpressLocals.coffee @@ -60,8 +60,7 @@ for paths in pathList logger.log "#{filePath}: #{hash}" fingerprints[filePath] = hash - if paths.length == 1 - path = paths[0] + for path in paths splitPath = path.split("/") filenameSplit = splitPath.pop().split(".") filenameSplit.splice(filenameSplit.length-1, 0, hash) From cbf656518f33ac6df64f488c7aec90d0b2a2f484 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Thu, 14 Dec 2017 11:24:47 +0000 Subject: [PATCH 11/13] remove versioned files from fingerprinting --- services/web/app/coffee/infrastructure/ExpressLocals.coffee | 5 ----- services/web/app/views/project/editor.pug | 1 - .../web/public/coffee/ide/editor/directives/aceEditor.coffee | 2 +- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/services/web/app/coffee/infrastructure/ExpressLocals.coffee b/services/web/app/coffee/infrastructure/ExpressLocals.coffee index 51b44a8996..74c4b242fc 100644 --- a/services/web/app/coffee/infrastructure/ExpressLocals.coffee +++ b/services/web/app/coffee/infrastructure/ExpressLocals.coffee @@ -39,15 +39,10 @@ getFileContent = (filePath)-> logger.log "Generating file fingerprints..." pathList = [ - ["#{jsPath}libs/#{fineuploader}.js"] ["#{jsPath}libs/require.js"] ["#{jsPath}ide.js"] ["#{jsPath}main.js"] ["#{jsPath}libraries.js"] - ["#{jsPath}#{ace}/ace.js","#{jsPath}#{ace}/mode-latex.js","#{jsPath}#{ace}/worker-latex.js","#{jsPath}#{ace}/snippets/latex.js"] - ["#{jsPath}libs/#{pdfjs}/pdf.js"] - ["#{jsPath}libs/#{pdfjs}/pdf.worker.js"] - ["#{jsPath}libs/#{pdfjs}/compatibility.js"] ["/stylesheets/style.css"] ["/stylesheets/ol-style.css"] ] diff --git a/services/web/app/views/project/editor.pug b/services/web/app/views/project/editor.pug index 582e0f3541..38ade1a6b2 100644 --- a/services/web/app/views/project/editor.pug +++ b/services/web/app/views/project/editor.pug @@ -156,7 +156,6 @@ block requirejs } } }; - window.aceFingerprint = "#{fingerprint(jsPath + lib('ace') + '/ace.js')}" window.aceWorkerPath = "#{aceWorkerPath}"; window.pdfCMapsPath = "#{pdfCMapsPath}" window.uiConfig = JSON.parse('!{JSON.stringify(uiConfig).replace(/\//g, "\\/")}'); diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor.coffee index 6908b25bce..ff5d1554e2 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor.coffee @@ -33,7 +33,7 @@ define [ if !ace.config._moduleUrl? ace.config._moduleUrl = ace.config.moduleUrl ace.config.moduleUrl = (args...) -> - url = ace.config._moduleUrl(args...) + "?fingerprint=#{window.aceFingerprint}" + url = ace.config._moduleUrl(args...) return url App.directive "aceEditor", ($timeout, $compile, $rootScope, event_tracking, localStorage, $cacheFactory, metadata, graphics, preamble, files, $http, $q) -> From 507503fe89ecae00f6976cac1fc0471d0c943c91 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Thu, 14 Dec 2017 11:36:33 +0000 Subject: [PATCH 12/13] remove old .gitignore paths --- services/web/.gitignore | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/services/web/.gitignore b/services/web/.gitignore index d0053e47c8..3830036f24 100644 --- a/services/web/.gitignore +++ b/services/web/.gitignore @@ -67,18 +67,9 @@ public/minjs/ Gemfile.lock -public/js/libs/fineuploader-5.15.4.*.js -public/js/libs/fineuploader-*.js -public/js/libs/pdfjs-*/compatibility.*.js -public/js/libs/pdfjs-*/pdf.*.js -public/js/libs/pdfjs-*/pdf.worker.*.js -public/js/libs/require.*.js public/stylesheets/ol-style.*.css public/stylesheets/style.*.css -public/js/ace-*/ace.*.js -public/js/ace-*/mode-latex.*.js -public/js/ace-*/snippets/latex.*.js -public/js/ace-*/worker-latex.*.js + *.swp .DS_Store From bf276b08142ed3fbb752bee8ea3c9d2d4f26729f Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Thu, 14 Dec 2017 12:11:13 +0000 Subject: [PATCH 13/13] ripped file fingerprinting out --- .../infrastructure/ExpressLocals.coffee | 66 +++++++------------ services/web/app/views/layout.pug | 12 ++-- services/web/app/views/project/editor.pug | 18 ++--- 3 files changed, 38 insertions(+), 58 deletions(-) diff --git a/services/web/app/coffee/infrastructure/ExpressLocals.coffee b/services/web/app/coffee/infrastructure/ExpressLocals.coffee index 74c4b242fc..002a10ca89 100644 --- a/services/web/app/coffee/infrastructure/ExpressLocals.coffee +++ b/services/web/app/coffee/infrastructure/ExpressLocals.coffee @@ -12,7 +12,6 @@ Modules = require "./Modules" Url = require "url" PackageVersions = require "./PackageVersions" htmlEncoder = new require("node-html-encoder").Encoder("numerical") -fingerprints = {} hashedFiles = {} Path = require 'path' Features = require "./Features" @@ -31,49 +30,39 @@ getFileContent = (filePath)-> filePath = Path.join __dirname, "../../../", "public#{filePath}" exists = fs.existsSync filePath if exists - content = fs.readFileSync filePath + content = fs.readFileSync filePath, "UTF-8" return content else - logger.log filePath:filePath, "file does not exist for fingerprints" + logger.log filePath:filePath, "file does not exist for hashing" return "" -logger.log "Generating file fingerprints..." +logger.log "Generating file hashes..." pathList = [ - ["#{jsPath}libs/require.js"] - ["#{jsPath}ide.js"] - ["#{jsPath}main.js"] - ["#{jsPath}libraries.js"] - ["/stylesheets/style.css"] - ["/stylesheets/ol-style.css"] + "#{jsPath}libs/require.js" + "#{jsPath}ide.js" + "#{jsPath}main.js" + "#{jsPath}libraries.js" + "/stylesheets/style.css" + "/stylesheets/ol-style.css" ] -for paths in pathList - contentList = _.map(paths, getFileContent) - content = contentList.join("") +for path in pathList + content = getFileContent(path) hash = crypto.createHash("md5").update(content).digest("hex") - _.each paths, (filePath)-> - logger.log "#{filePath}: #{hash}" - fingerprints[filePath] = hash + + splitPath = path.split("/") + filenameSplit = splitPath.pop().split(".") + filenameSplit.splice(filenameSplit.length-1, 0, hash) + splitPath.push(filenameSplit.join(".")) - for path in paths - 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 + hashPath = splitPath.join("/") + hashedFiles[path] = hashPath + + fsHashPath = Path.join __dirname, "../../../", "public#{hashPath}" + fs.writeFileSync(fsHashPath, content) -getFingerprint = (path) -> - if fingerprints[path]? - return fingerprints[path] - else - logger.err "No fingerprint for file: #{path}" - return "" - -logger.log "Finished generating file fingerprints" +logger.log "Finished hashing static content" cdnAvailable = Settings.cdn?.web?.host? darkCdnAvailable = Settings.cdn?.web?.darkHost? @@ -135,14 +124,9 @@ module.exports = (app, webRouter, privateApiRouter, publicApiRouter)-> if opts.hashedPath path = hashedFiles[path] - doFingerPrint = opts.fingerprint != false - if !opts.qs? opts.qs = {} - if !opts.qs?.fingerprint? and doFingerPrint - opts.qs.fingerprint = getFingerprint(path) - if opts.cdn != false path = Url.resolve(staticFilesBase, path) @@ -160,7 +144,7 @@ module.exports = (app, webRouter, privateApiRouter, publicApiRouter)-> if opts?.hashedPath hashedPath = hashedFiles[path] return Url.resolve(staticFilesBase, hashedPath) - return Url.resolve(staticFilesBase, path) + "?fingerprint=" + getFingerprint(path) + return Url.resolve(staticFilesBase, path) res.locals.buildImgPath = (imgFile)-> path = Path.join("/img/", imgFile) @@ -245,10 +229,6 @@ module.exports = (app, webRouter, privateApiRouter, publicApiRouter)-> return req.query?[field] next() - webRouter.use (req, res, next)-> - res.locals.fingerprint = getFingerprint - next() - webRouter.use (req, res, next)-> res.locals.formatPrice = SubscriptionFormatters.formatPrice next() diff --git a/services/web/app/views/layout.pug b/services/web/app/views/layout.pug index 5aa41c56c7..f203d29357 100644 --- a/services/web/app/views/layout.pug +++ b/services/web/app/views/layout.pug @@ -57,7 +57,7 @@ html(itemscope, itemtype='http://schema.org/Product') script(type="text/javascript"). window.csrfToken = "#{csrfToken}"; - script(src=buildJsPath("libs/jquery-1.11.1.min.js", {fingerprint:false})) + script(src=buildJsPath("libs/jquery-1.11.1.min.js")) script(type="text/javascript"). var noCdnKey = "nocdn=true" var cdnBlocked = typeof jQuery === 'undefined' @@ -68,7 +68,7 @@ html(itemscope, itemtype='http://schema.org/Product') block scripts - script(src=buildJsPath("libs/angular-1.6.4.min.js", {fingerprint:false})) + script(src=buildJsPath("libs/angular-1.6.4.min.js")) script. window.sharelatex = { @@ -143,8 +143,8 @@ html(itemscope, itemtype='http://schema.org/Product') "paths" : { "moment": "libs/#{lib('moment')}", "fineuploader": "libs/#{lib('fineuploader')}", - "main": "#{buildJsPath('main.js', {hashedPath:settings.useMinifiedJs, fingerprint:false, removeExtension:true})}", - "libraries": "#{buildJsPath('libraries.js', {hashedPath:settings.useMinifiedJs, fingerprint:false, removeExtension:true})}", + "main": "#{buildJsPath('main.js', {hashedPath:settings.useMinifiedJs, removeExtension:true})}", + "libraries": "#{buildJsPath('libraries.js', {hashedPath:settings.useMinifiedJs, removeExtension:true})}", }, "config":{ "moment":{ @@ -153,9 +153,9 @@ html(itemscope, itemtype='http://schema.org/Product') } }; script( - data-main=buildJsPath('main.js', {hashedPath:false, fingerprint:false}), + data-main=buildJsPath('main.js', {hashedPath:false}), baseurl=fullJsPath, - src=buildJsPath('libs/require.js') + src=buildJsPath('libs/require.js', {hashedPath:true}) ) include contact-us-modal diff --git a/services/web/app/views/project/editor.pug b/services/web/app/views/project/editor.pug index 38ade1a6b2..d1d0d94cf3 100644 --- a/services/web/app/views/project/editor.pug +++ b/services/web/app/views/project/editor.pug @@ -98,9 +98,9 @@ block requirejs script(type="text/javascript" src='/socket.io/socket.io.js') //- don't use cdn for workers - - var aceWorkerPath = buildJsPath(lib('ace'), {cdn:false,fingerprint:false}) - - var pdfWorkerPath = buildJsPath('/libs/' + lib('pdfjs') + '/pdf.worker', {cdn:false,fingerprint:false}) - - var pdfCMapsPath = buildJsPath('/libs/' + lib('pdfjs') + '/bcmaps/', {cdn:false,fingerprint:false}) + - var aceWorkerPath = buildJsPath(lib('ace'), {cdn:false}) + - var pdfWorkerPath = buildJsPath('/libs/' + lib('pdfjs') + '/pdf.worker', {cdn:false}) + - var pdfCMapsPath = buildJsPath('/libs/' + lib('pdfjs') + '/bcmaps/', {cdn:false}) //- We need to do .replace(/\//g, '\\/') do that '' -> '<\/script>' //- and doesn't prematurely end the script tag. @@ -126,14 +126,14 @@ block requirejs window.wikiEnabled = #{!!(settings.apis.wiki && settings.apis.wiki.url)}; window.requirejs = { "paths" : { - "mathjax": "#{buildJsPath('/libs/mathjax/MathJax.js', {cdn:false, fingerprint:false, qs:{config:'TeX-AMS_HTML'}})}", + "mathjax": "#{buildJsPath('/libs/mathjax/MathJax.js', {cdn:false, qs:{config:'TeX-AMS_HTML'}})}", "moment": "libs/#{lib('moment')}", "pdfjs-dist/build/pdf": "libs/#{lib('pdfjs')}/pdf", "pdfjs-dist/build/pdf.worker": "#{pdfWorkerPath}", "ace": "#{lib('ace')}", "fineuploader": "libs/#{lib('fineuploader')}", - "ide": "#{buildJsPath('ide.js', {hashedPath:settings.useMinifiedJs, fingerprint:false, removeExtension:true})}", - "libraries": "#{buildJsPath('libraries.js', {hashedPath:settings.useMinifiedJs, fingerprint:false, removeExtension:true})}", + "ide": "#{buildJsPath('ide.js', {hashedPath:settings.useMinifiedJs, removeExtension:true})}", + "libraries": "#{buildJsPath('libraries.js', {hashedPath:settings.useMinifiedJs, removeExtension:true})}", }, "waitSeconds": 0, "shim": { @@ -161,8 +161,8 @@ block requirejs window.uiConfig = JSON.parse('!{JSON.stringify(uiConfig).replace(/\//g, "\\/")}'); script( - data-main=buildJsPath("ide.js", {hashedPath:false, fingerprint:false}), + data-main=buildJsPath("ide.js", {hashedPath:false}), baseurl=fullJsPath, - data-ace-base=buildJsPath(lib('ace'), {fingerprint:false}), - src=buildJsPath('libs/require.js', {hashedPath:false}) + data-ace-base=buildJsPath(lib('ace')), + src=buildJsPath('libs/require.js', {hashedPath:true}) )