mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-22 08:26:16 -04:00
ace: Delete all $$INCLUDE_CSS
logic
The intention of the deleted code was to reduce the number of fetches, but it only saved a single fetch due to implementation flaws. The right way to reduce the number of fetches is to use a bundling technology such as webpack, and this change makes it easier to do so.
This commit is contained in:
parent
66d3ac3783
commit
b0862cd030
2 changed files with 9 additions and 84 deletions
|
@ -220,44 +220,6 @@ const minify = async (req, res) => {
|
|||
}
|
||||
};
|
||||
|
||||
// find all includes in ace.js and embed them.
|
||||
const getAceFile = async () => {
|
||||
let data = await fs.readFile(path.join(ROOT_DIR, 'js/ace.js'), 'utf8');
|
||||
|
||||
// Find all includes in ace.js and embed them
|
||||
const filenames = [];
|
||||
if (settings.minify) {
|
||||
const regex = /\$\$INCLUDE_[a-zA-Z_]+\((['"])([^'"]*)\1\)/gi;
|
||||
// This logic can be simplified via String.prototype.matchAll() once support for Node.js
|
||||
// v11.x and older is dropped.
|
||||
let matches;
|
||||
while ((matches = regex.exec(data)) != null) {
|
||||
filenames.push(matches[2]);
|
||||
}
|
||||
}
|
||||
|
||||
data += 'Ace2Editor.EMBEDED = Ace2Editor.EMBEDED || {};\n';
|
||||
|
||||
// Request the contents of the included file on the server-side and write
|
||||
// them into the file.
|
||||
await Promise.all(filenames.map(async (filename) => {
|
||||
// Hostname "invalid.invalid" is a dummy value to allow parsing as a URI.
|
||||
const baseURI = 'http://invalid.invalid';
|
||||
let resourceURI = baseURI + path.join('/static/', filename);
|
||||
resourceURI = resourceURI.replace(/\\/g, '/'); // Windows (safe generally?)
|
||||
|
||||
const [status, , body] = await requestURI(resourceURI, 'GET', {});
|
||||
const error = !(status === 200 || status === 404);
|
||||
if (!error) {
|
||||
data += `Ace2Editor.EMBEDED[${JSON.stringify(filename)}] = ${
|
||||
JSON.stringify(status === 200 ? body || '' : null)};\n`;
|
||||
} else {
|
||||
console.error(`getAceFile(): error getting ${resourceURI}. Status code: ${status}`);
|
||||
}
|
||||
}));
|
||||
return data;
|
||||
};
|
||||
|
||||
// Check for the existance of the file and get the last modification date.
|
||||
const statFile = async (filename, dirStatLimit) => {
|
||||
/*
|
||||
|
@ -366,7 +328,6 @@ const getFileCompressed = async (filename, contentType) => {
|
|||
};
|
||||
|
||||
const getFile = async (filename) => {
|
||||
if (filename === 'js/ace.js') return await getAceFile();
|
||||
if (filename === 'js/require-kernel.js') return requireDefinition();
|
||||
return await fs.readFile(path.join(ROOT_DIR, filename));
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue