ReadAlongs / Studio-Web

Suite of web packages for creating interactive ReadAlongs
https://readalong-studio.mothertongues.org/
Other
11 stars 9 forks source link

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

Closed joanise closed 3 weeks ago

joanise commented 4 weeks ago

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.

semanticdiff-com[bot] commented 4 weeks ago

Review changes with SemanticDiff.

Analyzed 2 of 2 files.

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

Filename Status
:heavy_check_mark: packages/studio-web/src/app/b64.service.ts 97.7% smaller
:heavy_check_mark: packages/studio-web/src/app/shared/download/download.service.ts 19.84% smaller
github-actions[bot] commented 4 weeks ago

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