Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: fonts are already base64 text, no need to re-base64 a second time #362

Merged
merged 1 commit into from
Oct 25, 2024

Conversation

joanise
Copy link
Member

@joanise joanise commented Oct 22, 2024

PR Goal?

Reduce the size of the Offline HTML file.

Fixes?

When we embed the fonts in the Offline HTML, we base64 encode them twice: once from the three .woff2 files into fonts.b64.css, and a second time putting that into the <link rel="stylesheet" href="..."> line in the .html file.

This is wasteful because the .css file is already plain text, having had its binary components b64 encoded already.

Instead, this PR proposes to wrap the verbatim contents of the .css file in a <style> element, which has the same effects.

The results are nice: a trivial readalong goes from 850kb down to 680kb, a saving of roughly 170kb in each RA we download as Offline HTML.

Feedback sought?

testing to make sure this doesn't break anything!

Priority?

low

Tests added?

no yet, no.

How to test?

These are tests I have also done:

Create a readalong or edit an existing one, download it as single file HTML, and see it is smaller but still works correctly, even if you network cable is unplugged.

Upload it back on the currently deployed app, and see you can keep editing, and downloading it from this version or the deployed one, differs in the size of the .html file but not in functionality.

Confidence?

Medium-high

Version change?

no, because while the .html file is different, it is still fully backwards compatible.

Copy link

semanticdiff-com bot commented Oct 22, 2024

Review changes with SemanticDiff.

Analyzed 2 of 2 files.

Overall, the semantic diff is 89% smaller than the GitHub diff.

Filename Status
✔️ packages/studio-web/src/app/b64.service.ts 97.7% smaller
✔️ packages/studio-web/src/app/shared/download/download.service.ts 19.84% smaller

Copy link
Contributor

github-actions bot commented Oct 22, 2024

PR Preview Action v1.4.8
Preview removed because the pull request was closed.
2024-10-25 15:28 UTC

Copy link
Collaborator

@roedoejet roedoejet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested, works. makes a lot of sense! nice catch @joanise !

@joanise joanise merged commit dd3b541 into main Oct 25, 2024
2 checks passed
@joanise joanise deleted the dev.ej/no-double-encode-fonts branch October 25, 2024 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants