-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
WIP: split .js
, load some asynchronously & on-demand, use ESM
#7586
Conversation
.js
, use ESM.js
, load some asynchronously & on-demand, use ESM
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.
Generally, any improvements to the JavaScript are welcome. The tricky part is that there are basically no tests for it, so it's super easy to break something. The current split out editor files are a typical example of that - it was tested by the author, me when merging and several issues were discovered months after merging in some not that frequently used features.
I think imports is something we can go for directly without a compatibility layer - we already started to use arrow functions two years ago and that was IMHO bigger drop in supported browsers than this.
<script defer data-cfasync="false" src="{% static 'vendor/mousetrap.js' %}{{ cache_param }}"></script> | ||
<script defer data-cfasync="false" src="{% static 'vendor/mousetrap-global-bind.js' %}{{ cache_param }}"></script> | ||
<script defer data-cfasync="false" src="{% static 'vendor/clipboard.js' %}{{ cache_param }}"></script> | ||
<!-- TODO separate bootstrap? https://getbootstrap.com/docs/5.1/getting-started/javascript/#using-bootstrap-as-a-module --> |
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.
We're still at Bootstrap 3.4.1, see #2916
import Cookies from "./vendor/js.cookie.js"; | ||
import autosize from "./vendor/autosize.js"; | ||
// TODO perf: import Mousetrap dynamically. | ||
import Mousetrap from "./vendor/mousetrap.js"; |
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.
Mousetrap is IMHO used on nearly every page - it is used to catch Ctrl+Enter for form submission.
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.
Yeah, I saw that. Still, adding a bind asynchronously is possible.
EDIT: nvm, some libs do weblate/weblate/static/attach-tribute-to.js Lines 2 to 5 in ae96c4a
A problem here is that the dependencies don't use ESM (native |
for more information, see https://pre-commit.ci
This pull request has been automatically marked as stale because there wasn’t any recent activity. It will be closed soon if no further action occurs. Thank you for your contributions! |
Proposed changes
This is super WIP, for now look at it as a discussion rather than a full-fledged MR.
In order to improve page loading performance, it would be cool to load some JS asynchronously and on-demand, and tree-shake some of it. Examples: shortcuts, syntax highlighting, username autocompletion.
Here's the audit I ran:
As you can see, on my PC it takes ~400ms to load a prefetched page (i.e. it's only rendering, not including network download). You can imagine it's a little worse on mobile.
First step to this is rewriting the scripts with imports.
This also makes the code easier to maintain as there's fewer global vars.
TODO:
Checklist
Other information