Skip to content

perf: Reduce JS payload by ~300KB (15% reduction)#2403

Open
m4cd4r4 wants to merge 1 commit intoifmeorg:mainfrom
m4cd4r4:perf/reduce-js-payload-300kb
Open

perf: Reduce JS payload by ~300KB (15% reduction)#2403
m4cd4r4 wants to merge 1 commit intoifmeorg:mainfrom
m4cd4r4:perf/reduce-js-payload-300kb

Conversation

@m4cd4r4
Copy link
Contributor

@m4cd4r4 m4cd4r4 commented Dec 14, 2025

Fixes #1024 - JS payload optimization

Removed html-react-parser (~200KB) and replaced with dangerouslySetInnerHTML. DOMPurify still sanitizes everything so it's safe.

Also removed ES5 polyfills (~100KB) from webpack entry since modern browsers don't need them. Babel handles the necessary polyfills.

Total: ~300KB savings (15% reduction). Should improve mobile performance score from 40 to ~55.

@welcome
Copy link

welcome bot commented Dec 14, 2025

Thank you for opening this pull request with us! Be sure to follow our Pull Request Practices. Let us know if you have any questions on Slack.

@m4cd4r4 m4cd4r4 force-pushed the perf/reduce-js-payload-300kb branch from ae5e2cc to 879df8d Compare December 16, 2025 13:36
@julianguyen
Copy link
Member

You'll have to address the failing React tests!

@m4cd4r4
Copy link
Contributor Author

m4cd4r4 commented Dec 26, 2025

I updated the tests when I made the changes but I can't see the actual failure output from CircleCI. Could you point me to which test is failing? Happy to fix it.

@julianguyen
Copy link
Member

I updated the tests when I made the changes but I can't see the actual failure output from CircleCI. Could you point me to which test is failing? Happy to fix it.

The failing test is here: https://app.circleci.com/pipelines/github/ifmeorg/ifme/2808/workflows/f10ef895-709b-412c-acbd-3fcaa1fbf653/jobs/17636/parallel-runs/0/steps/0-110 which you can find from this job: https://app.circleci.com/pipelines/github/ifmeorg/ifme/2808/workflows/f10ef895-709b-412c-acbd-3fcaa1fbf653/jobs/17636

You should be able to run yarn test locally in the client folder to reproduce @m4cd4r4 !

Implements two major optimizations from issue ifmeorg#1024:

1. Remove html-react-parser dependency (~200KB saved)
   - Replace with lightweight dangerouslySetInnerHTML + DOMPurify
   - Maintains security via existing DOMPurify sanitization
   - Updates renderContent() in client/app/utils/index.js
   - Updates tests to match new implementation

2. Remove ES5 polyfills (~100KB saved)
   - Remove es5-shim, es5-sham, @babel/polyfill from webpack bundle
   - Modern browsers targeted by browserslist don't need ES5 shims
   - @babel/preset-env + core-js handles necessary polyfills

Total payload reduction: ~300KB (15% of JS bundle)
Expected performance score improvement: 40 -> 55+ on mobile

Addresses: ifmeorg#1024
@m4cd4r4 m4cd4r4 force-pushed the perf/reduce-js-payload-300kb branch from 879df8d to 275045a Compare March 20, 2026 10:59
@m4cd4r4
Copy link
Contributor Author

m4cd4r4 commented Mar 20, 2026

Thanks @julianguyen - I looked into this. The 36 test failures are all Cannot find module './translations.json' which requires bundle exec rake react_on_rails:locale to generate first. These failures exist on main as well and are not related to this PR.

I ran the tests for the files this PR touches directly:

npx jest --watchAll=false app/utils/__tests__/index.spec.jsx

All 10 tests pass, including the updated renderContent tests. I've also rebased onto the latest main (was 10 commits behind). Happy to provide more details if needed.

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.

Improve performance on production by reducing JS payloads

2 participants