Skip to content
This repository was archived by the owner on Oct 10, 2023. It is now read-only.

Commit

Permalink
fix: raise max css size to 75kb
Browse files Browse the repository at this point in the history
AMP now allows 75kb of inline CSS (before 50kb)
  • Loading branch information
saitho committed Aug 21, 2021
1 parent d29645f commit 59b81f2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/Worker/ValidateCssWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class ValidateCssWorker extends AbstractCssWorker implements WorkerInterf
public async work() {
return new Promise<void>(async (resolve, reject) => {
if (!this.checkFileSize()) {
reject('[AMP] CSS file size extends 50kb!');
reject('[AMP] CSS file size extends 75kb!');
return;
}

Expand Down Expand Up @@ -65,6 +65,6 @@ export class ValidateCssWorker extends AbstractCssWorker implements WorkerInterf
protected checkFileSize(): boolean {
const byteSize = Buffer.from(this.css).byteLength;
console.debug('CSS byte size is: ' + byteSize);
return byteSize <= 50000;
return byteSize <= 75000;
}
}
}
20 changes: 10 additions & 10 deletions test/Worker/ValidateCssWorker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,29 @@ describe("ValidateCssWorker", () => {
.catch(() => done());
});
it("should fail on too large CSS", (done: DoneCallback) => {
const fiftyByteCss = `body { font-size: 15px; border: 1px solid black; }`; // this CSS is 50 byte
let overFiftykBytesCss = '';
const byteCss = `body {font-family: Arial, sans-serif; color: red, border: 1px solid black;}`; // this CSS is 75 byte
let overMaxBytesCss = '';
for (let i = 0; i < 1001; i++) {
overFiftykBytesCss = overFiftykBytesCss.concat(fiftyByteCss);
overMaxBytesCss = overMaxBytesCss.concat(byteCss);
}

const worker = new ValidateCssWorker();
worker.setCss(overFiftykBytesCss);
worker.setCss(overMaxBytesCss);
worker.work()
.then(() => done.fail('Validation succeeded even though it should not!'))
.catch(() => done());
});
it("should succeed on CSS being exactly 50kb", (done: DoneCallback) => {
const fiftyByteCss = `body { font-size: 15px; border: 1px solid black; }`; // this CSS is 50 byte
let exactlyFiftykBytesCss = '';
it("should succeed on CSS being exactly 75kb", (done: DoneCallback) => {
const byteCss = `body {font-family: Arial, sans-serif; color: red, border: 1px solid black;}`; // this CSS is 75 byte
let exactlyMaxBytesCss = '';
for (let i = 0; i < 1000; i++) {
exactlyFiftykBytesCss = exactlyFiftykBytesCss.concat(fiftyByteCss);
exactlyMaxBytesCss = exactlyMaxBytesCss.concat(byteCss);
}

const worker = new ValidateCssWorker();
worker.setCss(exactlyFiftykBytesCss);
worker.setCss(exactlyMaxBytesCss);
worker.work()
.then(() => done())
.catch(() => done.fail("Validation failed."));
});
});
});

0 comments on commit 59b81f2

Please sign in to comment.