From af367ade5a0904067705575e8e4d67422c73a513 Mon Sep 17 00:00:00 2001 From: muxator Date: Thu, 14 May 2020 01:54:57 +0200 Subject: [PATCH 1/2] assets: also use cache busting via query string in files imported from acs.js Before this change, a client would require two versions of the same assets (with and without randomVersionString), wasting resources and triggering all sorts of hard to debug inconsistencies. This change should have been part of 95fd5ce2a45e and completes it. --- src/node/handler/PadMessageHandler.js | 1 + src/static/js/ace.js | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/node/handler/PadMessageHandler.js b/src/node/handler/PadMessageHandler.js index 9e23fea21d4..bf69a3d2580 100644 --- a/src/node/handler/PadMessageHandler.js +++ b/src/node/handler/PadMessageHandler.js @@ -1076,6 +1076,7 @@ async function handleClientReady(client, message) var clientVars = { "skinName": settings.skinName, "skinVariants": settings.skinVariants, + "randomVersionString": settings.randomVersionString, "accountPrivs": { "maxRevisions": 100 }, diff --git a/src/static/js/ace.js b/src/static/js/ace.js index d06d902a6ba..efb27fc5fa3 100644 --- a/src/static/js/ace.js +++ b/src/static/js/ace.js @@ -237,7 +237,7 @@ function Ace2Editor() // disableCustomScriptsAndStyles can be used to disable loading of custom scripts if(!clientVars.disableCustomScriptsAndStyles){ - $$INCLUDE_CSS("../static/css/pad.css"); + $$INCLUDE_CSS("../static/css/pad.css?v=" + clientVars.randomVersionString); } var additionalCSS = _(hooks.callAll("aceEditorCSS")).map(function(path){ @@ -247,7 +247,7 @@ function Ace2Editor() return '../static/plugins/' + path; }); includedCSS = includedCSS.concat(additionalCSS); - $$INCLUDE_CSS("../static/skins/" + clientVars.skinName + "/pad.css"); + $$INCLUDE_CSS("../static/skins/" + clientVars.skinName + "/pad.css?v=" + clientVars.randomVersionString); pushStyleTagsFor(iframeHTML, includedCSS); @@ -321,7 +321,7 @@ window.onload = function () {\n\ var includedCSS = []; var $$INCLUDE_CSS = function(filename) {includedCSS.push(filename)}; $$INCLUDE_CSS("../static/css/iframe_editor.css"); - $$INCLUDE_CSS("../static/css/pad.css"); + $$INCLUDE_CSS("../static/css/pad.css?v=" + clientVars.randomVersionString); var additionalCSS = _(hooks.callAll("aceEditorCSS")).map(function(path){ @@ -331,7 +331,7 @@ window.onload = function () {\n\ return '../static/plugins/' + path } ); includedCSS = includedCSS.concat(additionalCSS); - $$INCLUDE_CSS("../static/skins/" + clientVars.skinName + "/pad.css"); + $$INCLUDE_CSS("../static/skins/" + clientVars.skinName + "/pad.css?v=" + clientVars.randomVersionString); pushStyleTagsFor(outerHTML, includedCSS); From 6af6c0098a9ba5ac43475e1616b8b20cdbc48550 Mon Sep 17 00:00:00 2001 From: muxator Date: Thu, 14 May 2020 01:59:10 +0200 Subject: [PATCH 2/2] minify: rebase relative urls in imported files. 4177b3f9434 moved the font-face declarations from src/static/css/pad.css to two imported files (src/static/css/pad/fonts.css, src/static/css/pad/toolbar.css) in a different directory. This results in the font files being invoked from CSSes residing in different directories in the minified and un-minified case. URLs in the src attribute are relative to the stylesheet path [0], and so we have to start requiring clean-css to rebase them. Before this change, the non minified casse worked by chance, because there were a lot of "..", which ended up resolving to the root of the site anyways. Fixes #3956 [0] https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/src --- src/node/utils/Minify.js | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/node/utils/Minify.js b/src/node/utils/Minify.js index 7cc05645bf4..2a9f2a5e73c 100644 --- a/src/node/utils/Minify.js +++ b/src/node/utils/Minify.js @@ -426,17 +426,17 @@ function compressCSS(filename, content, callback) /* * Changes done to migrate CleanCSS 3.x -> 4.x: * - * 1. Disabling rebase is necessary because otherwise the URLs for the web - * fonts become wrong. + * 1. Rework the rebase logic, because the API was simplified (but we have + * less control now). See: + * https://github.com/jakubpawlowicz/clean-css/blob/08f3a74925524d30bbe7ac450979de0a8a9e54b2/README.md#important-40-breaking-changes * - * EXAMPLE 1: - * /static/css/src/static/font/fontawesome-etherpad.woff - * instead of - * /static/font/fontawesome-etherpad.woff - * EXAMPLE 2 (this is more surprising): - * /p/src/static/font/opendyslexic.otf - * instead of - * /static/font/opendyslexic.otf + * EXAMPLE: + * The URLs contained in a CSS file (including all the stylesheets + * imported by it) residing on disk at: + * /home/muxator/etherpad/src/static/css/pad.css + * + * Will be rewritten rebasing them to: + * /home/muxator/etherpad/src/static/css * * 2. CleanCSS.minify() can either receive a string containing the CSS, or * an array of strings. In that case each array element is interpreted as @@ -447,7 +447,13 @@ function compressCSS(filename, content, callback) * "content" argument, but we have to wrap the absolute path to the CSS * in an array and ask the library to read it by itself. */ - new CleanCSS({rebase: false}).minify([absPath], function (errors, minified) { + + const basePath = path.dirname(absPath); + + new CleanCSS({ + rebase: true, + rebaseTo: basePath, + }).minify([absPath], function (errors, minified) { if (errors) { // on error, just yield the un-minified original, but write a log message console.error(`CleanCSS.minify() returned an error on ${filename} (${absPath}): ${errors}`);