-
-
Notifications
You must be signed in to change notification settings - Fork 9.2k
chore: minor reduction to inline svg/js code #11317
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
Conversation
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
⚡️ Lighthouse report for the deploy preview of this PR
|
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.
Thanks
I think we can consider it's not a breaking change
} | ||
|
||
|
||
function getQueryStringTheme() { |
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.
Can we reduce line breaks and useless indentation?
This doesn't matter much (if minimization is enabled), but it looks a bit messy
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.
Done! Let me know if you're fine with that!
I did it this way before as my aim was to keep the source clean rather than the output. Now that we've prioritized a clean output, I feel the source looks a bit messy now, though.
I'm starting to see the appeal to tc39/proposal-string-dedent.
30de303
to
362c71a
Compare
Thanks 👍 |
Pre-flight checklist
Motivation
I've been looking at the output of SVGO.dev and just trying to see where we could reduce the bundles further. (Switching to Preact, writing PostCSS plugins, hand-editing our SVGs, etc.)
These are two things I noticed during my review that were upstream. The changes are petty at best, but do reduce the inlined SVG/JS code by 0.25 KB and reduce the amount of JavaScript that is executed on the client. It's not much, but at least it's a quick win. ^-^'
Redundant XMLNS in SVG
Removes
xmlns
from the inlined sprite sheet icon.There's no need to specify the XMLNS when inlining an SVG into an HTML document. HTML rules apply rather than XML rules! I believe this is a safe change, inline SVGs have worked without
xmlns
all the way back with IE 9! The SVGs in this screenshot don't havexmlns
.Before vs. After in the Build Output (⬇️ 0.035 KB)
As an aside, these are the same sources you can reference for the rationale behind enabling
removeXMLNS
by default in the issue for better SVGO defaults.Reduce Theming JavaScript
This makes two changes:
disableSwitch
is enabled, there's no need to even inline the functions to read the theme setting from the URL or localStorage. The option to set it shouldn't be there anyway!disableSwitch
was enabled, it was still possible to force light mode through?docusaurus-theme=light
. ThedisableSwitch
option would now disable both the button and the query parameter.Before vs. After in the Build Output (⬇️ 0.206~ KB)
This may require consideration as it could be a breaking change. Depends on if the following is a supported scenario. A user sets
disableSwitch
totrue
, because they want to implement their own switch without swizzling, but they still wants Docusaurus to be responsible for thedata-theme
attribute. 🤔Test Plan
Test links
Deploy preview: https://deploy-preview-11317--docusaurus-2.netlify.app/