-
Notifications
You must be signed in to change notification settings - Fork 9
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
Refactor: reduce usage of jQuery #2646
Conversation
this will be used instead of jQuery's ready function
the logic for feature-detection (cookies) and for logging analytics for links can be done without jQuery.
this preserves our bug fix from bee42cf so that clicking on the modal backdrop does not click the radio button.
jQuery is now only needed in the enrollment index for the core app and the in-person app. the Javascript for making AJAX requests could be converted to plain Javascript, but that code does a lot, so not going to refactor it as part of this effort.
c42017b
to
180206f
Compare
💯 💯 💯 💯 💯 💯 💯 |
This is looking great, and it's so easy to follow the commit history @angela-tran, thanks! I'm noticing one thing though. The app runs fine but in the browser console I see that in I think this happens because these templates don't extend |
extract inline script as an include template that is used in both the core base template and the in-person agency base template.
One consequence of this was that the custom validity messages were not being shown, so definitely glad you brought this up. 💯 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change in e7a2ebe looks good! I also tested the reCAPTCHA feature (I had overlooked testing it during my first review) and it works fine 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extensively tested the Benefits application flow on Firefox, Safari and Chrome:
- Going thru the full app with keyboard only
- Opening, closing, navigating thru modals with keyboard only
- Clicking in and out of modals, around modals, outside of modals
- Filling out the agency card form and triggering various validation states
- Spinner
- reCAPTCHA
Really well done on this PR and all the documentation! Making a big improvement on performance and code. 5 stars.
Part of #2493
This PR makes it so we only use jQuery for enrollment. This allows us to stop loading jQuery on every page.
Context:
I originally set out to extract inline Javascript as separate files to be loaded in with
async
ordefer
. A lot of them would have to bedefer
since they depend onjQuery
being loaded and available.I tried it out and saw that the performance change was negligible. There was basically no difference.
It seemed then that a more impactful change would be to reduce the need for jQuery. A lot of what we were doing with jQuery can be done with plain Javascript that is well-supported by all modern browsers.
Using https://youmightnotneedjquery.com/ and https://tobiasahlin.com/blog/move-from-jquery-to-vanilla-javascript/#document-ready as reference and testing each change thoroughly, I was able to convert over all inline Javascript except for the ones on
core/enrollment/index.html
andin_person/enrollment/index.html
since the code there involves making AJAX requests and is more difficult to convert over.This change showed performance improvement, specifically with First Contentful Paint and Largest Contentful Paint times, according to Lighthouse. If we want to optimize further, another PR could extract inline Javascript out to separate files and load them with
async
now that they don't depend on jQuery.Before
After