diff --git a/.github/workflows/node.yml b/.github/workflows/node.yml index b5aec1de0..d2ddefe80 100644 --- a/.github/workflows/node.yml +++ b/.github/workflows/node.yml @@ -32,3 +32,4 @@ jobs: - run: npm run check-format --prefix ./assets - run: npm run test --prefix ./assets - run: npm run deploy --prefix ./tracker + - run: npm run report-sizes --prefix ./tracker diff --git a/tracker/package.json b/tracker/package.json index 35c3f40bf..d1b222583 100644 --- a/tracker/package.json +++ b/tracker/package.json @@ -2,6 +2,7 @@ "scripts": { "deploy": "node compile.js", "test": "npm run deploy && npx playwright test --config=./test/support/playwright.config.js", + "report-sizes": "node report-sizes.js", "start": "node test/support/server.js" }, "license": "MIT", diff --git a/tracker/report-sizes.js b/tracker/report-sizes.js new file mode 100644 index 000000000..01f63ab43 --- /dev/null +++ b/tracker/report-sizes.js @@ -0,0 +1,28 @@ +const fs = require('fs'); +const path = require('path'); +const { execSync } = require('child_process'); + +const PrivTrackerDir = '../priv/tracker/js/'; + +const toReport = [ + 'plausible.js', + 'plausible.pageleave.js', + 'plausible.manual.pageleave.js', + 'plausible.hash.pageleave.js' +]; + +const results = []; + +toReport.forEach((filename) => { + const filePath = path.join(PrivTrackerDir, filename); + if (fs.statSync(filePath).isFile()) { + results.push({ + 'Filename': filename, + 'Real Size (Bytes)': fs.statSync(filePath).size, + 'Gzipped Size (Bytes)': execSync(`gzip -c -9 "${filePath}"`).length, + 'Brotli Size (Bytes)': execSync(`brotli -c -q 11 "${filePath}"`).length + }); + } +}); + +console.table(results)